ZOJ 3687 The Review Plan I 解题报告
2013-07-27 18:45
253 查看
题目
比赛
题意:
n天要复习n本书,每天只能复习一本。有些天不能复习有些书,求可行的方案数。
题解:
因为n很小,所以可以用容斥做。注意m行不能复习的情况里面有矛盾的。
比赛
题意:
n天要复习n本书,每天只能复习一本。有些天不能复习有些书,求可行的方案数。
题解:
因为n很小,所以可以用容斥做。注意m行不能复习的情况里面有矛盾的。
//Time:320ms //Memory:180KB //Length:1090B #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; #define MAXN 60 #define MOD 55566677 int ans; int pre[MAXN],jie[MAXN]; int a[MAXN],b[MAXN]; int n,m; void dfs(int h,int cnt,int ty) { if(h==m) { ans=(ans+(cnt%2?-1:1)*jie[n-cnt]+MOD)%MOD; return ; } dfs(h+1,cnt,ty); if(!(pre[h]&ty)) dfs(h+1,cnt+1,ty|(1<<h)); } int main() { //freopen("/home/moor/Code/input","r",stdin); jie[0]=1; for(int i=1;i<MAXN;++i) jie[i]=(long long)jie[i-1]*i%MOD; bool flag; while(scanf("%d%d",&n,&m)==2) { for(int i=0;i<m;++i) { flag=0; scanf("%d%d",&a[i],&b[i]); pre[i]=0; for(int j=0;j<i;++j) { int cnt=0; cnt+=(a[i]==a[j]); cnt+=(b[i]==b[j]); if(cnt==1) pre[i]|=1<<j; else if(cnt==2) flag=1; } if(flag) --i,--m; } ans=0; dfs(0,0,0); printf("%d\n",ans); } return 0; }
相关文章推荐
- ZOJ 3687 The Review Plan I(禁位棋盘+dfs)
- zoj-3687-The Review Plan I(禁位排序)
- zoj 3687 The Review Plan I 禁位排列 棋盘多项式
- ZOJ 3687 B The Review Plan I
- ZOJ 3687 The Review Plan I(禁位排列)
- ZOJ 3687 The Review Plan I
- ZOJ 3687 The Review Plan I 禁位排列 | 容斥原理
- ZOJ 3772 Calculate the Function 解题报告
- zoj 3688 The Review Plan II(容斥原理+禁位排列+逆元)
- ZOJ 3256 Tour in the Castle 解题报告(插头DP)
- ZOJ 3430 Detect the Virus 解题报告
- ZOJ 1713 (Haiku Review)解题报告
- ZOJ 3688 C The Review Plan II
- ZOJ 3313-3321 The 10th Zhejiang University Programming Contest 部分题目解题报告
- ZOJ 1090 - The Circumference of the Circle 解题报告
- ZOJ 3466 The Hive II 解题报告(插头DP)
- zoj 3688 The Review Plan II
- ZOJ 3432 Find the Lost Sock 解题报告
- 1017. The Best Peak Shape (35)解题报告
- 浙江大学ZOJ 1006题 解题报告