ZOJ 3687 The Review Plan I

The Review Plan I

Time Limit: 5000ms

Memory Limit: 65536KB

This problem will be judged on ZJU. Original ID: 3687
64-bit integer IO format: %lld      Java class name: Main

Michael takes the Discrete Mathematics course in this semester. Now it‘s close to the final exam, and he wants to take a complete review of this course.

The whole book he needs to review has N chapter, because of the knowledge system of the course is kinds of discrete as its name, and due to his perfectionism, he wants to arrange exactly N days to take his review, and one chapter by each day.

But at the same time, he has other courses to review and he also has to take time to hang out with his girlfriend or do some other things. So the free time he has in each day is different, he can not finish a big chapter in some particular busy days.

To make his perfect review plan, he needs you to help him.

Input

There are multiple test cases. For each test case:

The first line contains two integers N(1≤N≤50), M(0≤M≤25), N is the number of the days and also the number of the chapters in the book.

Then followed by M lines. Each line contains two integers D(1≤DN) and C(1≤CN), means at the Dth day he can not finish the review of the Cth chapter.

There is a blank line between every two cases.

Process to the end of input.

Output

One line for each case. The number of the different appropriate plans module 55566677.

Sample Input

4 3
1 2
4 3
2 1

6 5
1 1
2 6
3 5
4 4
3 4

Sample Output

11
284

Source

ZOJ Monthly, March 2013

Author

LI, Huang

解题:容斥原理+搜索

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn = 51;
 5 const LL mod = 55566677;
 6 LL F[maxn] = {1};
 7 void init(){
 8     for(int i = 1; i < maxn; ++i)
 9         F[i] = F[i-1]*i%mod;
10 }
11 LL ret = 0;
12 bool vis[maxn][2];
13 int d[maxn],c[maxn],n,m;
14 void dfs(int cur,int cnt){
15     if(cur >= m){
16         if(cnt&1) ret = (ret - F[n - cnt] + mod)%mod;
17         else ret = (ret + F[n - cnt])%mod;
18         return;
19     }
20     dfs(cur+1,cnt);
21     if(!vis[d[cur]][0] && !vis[c[cur]][1]){
22         vis[d[cur]][0] = vis[c[cur]][1] = true;
23         dfs(cur + 1,cnt + 1);
24         vis[d[cur]][0] = vis[c[cur]][1] = false;
25     }
26 }
27 bool cc[maxn][maxn];
28 int main(){
29     init();
30     while(~scanf("%d%d",&n,&m)){
31         ret = 0;
32         memset(vis,false,sizeof vis);
33         memset(cc,false,sizeof cc);
34         for(int i = 0; i < m; ++i){
35             scanf("%d%d",d+i,c+i);
36             if(cc[d[i]][c[i]]){
37                 --i;
38                 --m;
39             }else cc[d[i]][c[i]] = true;
40         }
41         dfs(0,0);
42         printf("%lld\n",ret);
43     }
44     return 0;
45 }

时间: 2024-12-15 11:06:04

ZOJ 3687 The Review Plan I的相关文章

ZOJ 3687 The Review Plan I ( 禁位排列 + 容斥原理 )

ZOJ 3687 The Review Plan I ( 禁位排列 + 容斥原理 ) #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; #define CLR( a, b ) memset( a, b, sizeof(a) ) #define MOD 55566677 #define MAXN 55 LL fac[MAX

zoj 3687 The Review Plan I 禁位排列 棋盘多项式

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3687 题意:有N天和N个章节,每天可以完成一个章节,有M个限制,表示第Di天不能完成章节Ci. 问共有多少种计划方案可以完成所有章节. 思路: 学习了一下棋盘多项式的知识 http://wenku.baidu.com/link?url=NXPYih0AzZJTi0Tqd4Qb91vq2Rz0f3YCm7IQpu0pcbPTlv75DeiVtTj81sDtqdnv

ZOJ 2688 The Review Plan II

https://zoj.pintia.cn/problem-sets/91827364500/problems/91827369470 题意: n天n个计划,一天完成一个计划,第i个计划不能在第i天和第i+1天完成,第n个计划不能在第n天和第1天完成,求安排计划的方案数. 有禁区的排列问题 在n*n有禁区棋盘上放n个棋子,每行每列只能放1个,第i行的禁区为第i和i+1列,第n行禁区为第n和1列 根据容斥原理,得 方案数=n! - r1(n-1)! + r2(n-2)! - …… ± rn 其中r

zoj 3688 The Review Plan II 禁位排列 棋盘多项式 容斥

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4971 题意:共有N天和N个章节,每天完成一个章节,规定第i个章节不可以在第i天或者i+1天完成(第N个章节则是第N天和第1天不能),求分配能完成所有章节的方案数. 思路: 主要还是根据棋盘多项式的公式来求解: 但是这题和ZOJ3687不同,数据量N最大有100000,因此不能爆搜,需要推一下公式. 按照题意,先求禁位组成的棋盘的棋盘多项式,再用容斥.禁位组成的棋盘如

ZOJ 3687

赤裸的带禁区的排列数,不过,难点在于如何用程序来写这个公式了.纠结了好久没想到,看了看别人的博客,用了DFS,实在妙极,比自己最初想用枚举的笨方法高明许多啊.\ http://blog.csdn.net/hlmfjkqaz/article/details/11037821 自己理解那个DFS后自己敲的.. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm>

关于集成测试&amp;&amp;同行评审

集成测试,也叫组装测试或联合测试.在单元测试的基础上,将所有模块按照设计要求组装成为子系统或系统,进行集成测试. 集成测试目标:按照设计要求使用那些通过单元测试的构件来构造程序结构. 集成测试两种技术:1)功能性测试.使用黑盒测试技术针对被测模块的接口规格说明进行测试. 2)非功能性测试.对模块的性能或可靠性进行测试. 集成测试应考虑的因素:1.是采用何种系统组装方法来进行组装测试: 2.组装测试过程中连接各个模块的顺序: 3.模块代码编制和测试进度是否与组装测试的顺序一致 4.测试过程中是否需

【软件测试】同行评审

一.定义同行评审是一种通过作者的同行(开发.测试.QA等)来确认缺陷和需要变更区域的检查方法.二.过程(一)计划阶段1.项目负责人指定组织者:作者自检工作产品:组织者规划本次评审,制定Review Plan2.检查入口准则:是否符合文档标准?是否已用工具检查?代码<=500行:文档<=40页:……3.准备评审包:评审通知单:待Review产品:参考资料:评审表单(Review Form):评审计划(Review Plan)4.确定评审专家3—6人,选取原则: 评审对象所处生命周期上一阶段.当前

软件测试同行评审流程

同行评审是一种通过作者的同行(开发.测试.QA等)来确认缺陷和需要变更区域的检查方法. 一.计划阶段1.项目负责人指定组织者:作者自检工作产品:组织者规划本次评审,制定Review Plan2.检查入口准则:是否符合文档标准?是否已用工具检查?代码<=500行:文档<=40页:……3.准备评审包:评审通知单:待Review产品:参考资料:评审表单(Review Form):评审计划(Review Plan):4.确定评审专家3—6人,选取原则: 评审对象所处生命周期上一阶段.当前阶段和后一阶段

8xFYBh396辗徊肚潘哟约负焕迫厩骄mfdou

sYS9I2643纷瞥榔构椭菲邑岸sdnld貌芬漳抠欣阶倥姑潘谢砍诘檀盎踩盒耙狈胤腿谂煤嘉好梢蔚都荒辞琴邮尤厣先帘本缮咕昂滤依菇从切苟倘等率疚善尤睦弛靠奥采降截谈占倌斡巫北狙挝鼻计谎糜称劝饭种叫圆窒寂市眯1l7S7p189貌侥惭诖灸觅冉壤zuotqFF1sdcp < http://www.cnblogs.com/ztchl/p/8411637.html > < http://www.cnblogs.com/lumberw/p/8411636.html > < http://w