ZOJ 3687 The Review Plan I 容斥原理/禁位排列
2013-05-26 23:25
274 查看
题意:
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4970
题解:
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4970
题解:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define MOD 55566677 #define lint long long #define MAXN 52 int fa[MAXN]; int n, m; int a[MAXN][2]; bool ban[MAXN][MAXN]; bool vis1[MAXN], vis2[MAXN]; int ret; void init() { fa[0] = 1; for(int i = 1; i <= 50; i++) fa[i] = ((lint)fa[i-1] * i) % MOD; // for(int i = 1; i <= 50; i++) // printf("%d\n", fa[i]); } void In_Exclusion(int i, int num) //i表示第i个条件,num表示条件数目 { if(i > m) { if(num & 1) ret = (ret - fa[n-num]) % MOD; else ret = (ret + fa[n-num]) % MOD; return; } In_Exclusion(i + 1, num); //第i个条件不用 if(vis1[a[i][0]] == false && vis2[a[i][1]] == false) { vis1[a[i][0]] = vis2[a[i][1]] = true; In_Exclusion(i + 1, num + 1); vis1[a[i][0]] = vis2[a[i][1]] = false; } } int main() { init(); while(scanf("%d%d",&n,&m) != EOF) { memset(ban, 0, sizeof(ban)); memset(vis1, 0, sizeof(vis1)); memset(vis2, 0, sizeof(vis2)); for(int i = 1; i <= m; i++) { scanf("%d%d", &a[i][0], &a[i][1]); if(ban[a[i][0]][a[i][1]] == false) ban[a[i][0]][a[i][1]] = true; else {m--, i--;} } ret = 0; In_Exclusion(1, 0); printf("%d\n", (ret % MOD + MOD) % MOD); } return 0; }
相关文章推荐
- zoj 3687 The Review Plan I
- ZOJ 3687 The Review Plan I 解题报告
- zoj 3688 The Review Plan II(容斥原理+禁位排列+逆元)
- ZOJ 3687 The Review Plan I
- ZOJ 3687 The Review Plan I(禁位棋盘+dfs)
- ZOJ 3687 B The Review Plan I
- ZOJ 3687 The Review Plan I 禁位排列 | 容斥原理
- zoj 3687 The Review Plan I 禁位排列 棋盘多项式
- ZOJ 3688 C The Review Plan II
- ZOJ 3687 The Review Plan I(禁位排列)
- zoj-3687-The Review Plan I(禁位排序)
- zoj 3688 The Review Plan II
- The Review Plan I 禁为排列
- Why are some of the tables in my query missing from the plan?
- about the plan
- Review of Debugging the development process 6. Constant, Unceasing Improvement
- 安装完Office 2007打开提示:The setup controller has encountered a problem during instll.Please review the log files for further inf 的解决方
- Book Review of Dynamics of Software Development--Get their heads into the game
- Your app contains non-public API usage. Please review the errors, correct them, and resubmit your ap
- Review of the J2EE Blueprint 1