当前位置:网站首页>3059. Sculpture (jzoj)
3059. Sculpture (jzoj)
2022-07-26 01:22:00 【FKJDASOI】
Problem description :
Wcyz In order to welcome the centennial celebration , Beautify the campus , Invited alumni stupid general n A sculpture , Ready to be placed on campus , The whole campus can be abstracted into a n × n n\times n n×n Large grid of , Every 1 × 1 1\times 1 1×1 At most one sculpture can be placed in the grid , But some 1 × 1 1\times 1 1×1 There happens to be a canteen or lake on the grid , These grids cannot be used for placing sculptures , The shape of each sculpture is the same , In this way, the exchange arrangement in the same resettlement plan is one . Any sculpture in the same row or column is illegal .
The school wants to know how many resettlement schemes there are , Stupid wants to choose the best one , Benben wants you to tell him the number of schemes .
input:
first line , Two integers n,m(n<=20,m<=10), Space off ,n Express nn Large grid of ,m It means that the position of the sculpture cannot be placed
The second line goes to m+1 That's ok , Two numbers per line x,y, Separate with spaces , Representation coordinates (x,y) Of 11 No sculptures can be placed on the grid .
output
a number , Number of schemes ( Number of schemes <=2^63-1)
sample input
6 7
1 1
2 1
2 2
3 3
3 4
4 3
4 4
sample output
184
hint
n<=20,m<=10
Ideas
Seeing the title, we can easily think of the number of schemes that can be filled in by pop search , But such time complexity explodes , by O ( 2 n × n ) O(2^n\times n) O(2n×n), You can only get 10 points .
Smart little friends can definitely think of pressure DP 了 , The time complexity is O ( 2 m × m ) O(2^m\times m) O(2m×m), Pass easily , But this konjaku doesn't press , Here is another way of thinking, inclusive .
First , Let's imagine the basic model of inclusion and exclusion in our mind , That is, three circles intersect , Calculate the area of the whole pattern .
Are we just adding the areas of three large circles first , Subtract the three middle circles , Finally, add a small circle in the middle .
We can also boldly guess the area of the whole figure , In fact, it is to add graphics that only contain an odd number of sets , Subtract figures that contain an even number of sets .
Get down to business , We can easily conclude that the total number of schemes without obstacles and problems is ( n − 1 ) ! (n-1)! (n−1)!, Then we just need to come up with an illegal plan , Then subtract the two numbers, which is the answer .
For illegal , We consider filling in a number within the obstacle range , Write it down as r 1 r1 r1, We can use search to find r 1 r1 r1.
r 1 r1 r1 The last row and column cannot be filled , And the rest of the ( n − 1 ) × ( n − 1 ) (n-1)\times (n-1) (n−1)×(n−1) The grid of , No matter what plan we have , Because the front is illegal, it is illegal , The number of programmes is r 1 × ( n − 1 ) ! r1\times (n-1)! r1×(n−1)!. Let's carry out tolerance and exclusion , Because the situation of filling in two numbers must be within the situation of filling in only one number , If we reduce more, we will r 2 × ( n − 2 ) ! r2\times (n-2)! r2×(n−2)! add , Finally, keep going , Find the total number of all illegal schemes , Let's preprocess factorial , Total time complexity O ( 2 m ) O(2^m) O(2m).
The code is ugly .
code:
#include<bits/stdc++.h>
using namespace std;
long long n,m,r[31],c[31],used[3][31],x[31],y[31];
long long ans=0;
void dfs(int dep,int s,int l)
{
if (s==l)
{
r[l]++;
return ;
}
if (dep>m)return ;
if (!used[1][x[dep]]&&!used[2][y[dep]])
{
used[1][x[dep]]=used[2][y[dep]]=1;
dfs(dep+1,s+1,l);
used[1][x[dep]]=used[2][y[dep]]=0;
}
dfs(dep+1,s,l);
return ;
}
int main()
{
cin>>n>>m;
for (int i=1;i<=m;i++){
cin>>x[i]>>y[i];
}
for (int i=1;i<=m;i++)
dfs(1,0,i);
c[1]=1;
c[0]=1;
for (int i=2;i<=n;i++)
c[i]=c[i-1]*i;
ans=c[n];
for (int i=1;i<=m;i++)
{
if (i%2==1)
ans-=c[n-i]*r[i];
else ans+=c[n-i]*r[i];
}
cout<<ans;
return 0;
}
边栏推荐
- 【纪中】2022.7.16 1432.输油管道
- How to switch IP and move bricks with mobile game simulator
- # 浏览器开发使用技巧
- android sqlite先分组后排序左连查询
- 格式化JS代码,调试JS代码
- 【Go】如何控制协程的最大并发数
- The second China rust developer conference is coming, and the complete agenda has been exposed!
- [go] III. The simplest restful API server
- 网络性能评估工具 ping/mtr
- 数据库系统原理与应用教程(055)—— MySQL 查询(十七):数学函数的用法
猜你喜欢
![[ickim 2022] the Fourth International Conference on knowledge and information management](/img/e0/1d7aebc6a6fe42c4f4ddd47a2045ec.jpg)
[ickim 2022] the Fourth International Conference on knowledge and information management

Prime Ring Problem

MulDA: A Multilingual Data Augmentation Framework for Low-Resource Cross-Lingual NER 阅读笔记

Google gson usage details

当博客被黑客攻击时该怎么办?
![[Code] refers to the repeated number in the offer 03 array](/img/83/50f5157c363d46f38f6e4ef7fae3b2.png)
[Code] refers to the repeated number in the offer 03 array

NIO简易示例

The gym closes 8000 stores a year. How does the studio that bucks the trend and makes profits open?

FreeBSD bNXT Ethernet driver source code reading record 2:

Leetcode 537. complex multiplication (netizens' thoughts, ashamed)
随机推荐
Linear relationship between vectors
聚势|海泰方圆亮相第五届数字中国建设峰会
加载dll失败
JDBC connection database (idea version)
Redis数据结构详解,结合书本
RHCE之at和crontab命令详解及chrony部署
ORACLE——iSupplier 门户开票错误
What is the dynamic IP address? Why do you recommend dynamic IP proxy?
Two stage submission and three stage submission
Format JS code and debug JS code
NiO simple example
How to obtain the cash flow data of advertising services to help analyze the advertising effect?
Optimization of tableview
MulDA: A Multilingual Data Augmentation Framework for Low-Resource Cross-Lingual NER 阅读笔记
Tutorial on principles and applications of database system (056) -- MySQL query (18): usage of other types of functions
Arthas watch 命令查看数组中对象的属性
Transfer learning - getting started
[go] how to control the maximum number of concurrent processes
格式化JS代码,调试JS代码
[CTF] crypto preliminary basic outline