ZOJ 3687 The Review Plan I
The Review Plan I
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≤D≤N) and C(1≤C≤N), 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
Author
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
const LL mod = ;
LL F[maxn] = {};
void init(){
for(int i = ; i < maxn; ++i)
F[i] = F[i-]*i%mod;
}
LL ret = ;
bool vis[maxn][];
int d[maxn],c[maxn],n,m;
void dfs(int cur,int cnt){
if(cur >= m){
if(cnt&) ret = (ret - F[n - cnt] + mod)%mod;
else ret = (ret + F[n - cnt])%mod;
return;
}
dfs(cur+,cnt);
if(!vis[d[cur]][] && !vis[c[cur]][]){
vis[d[cur]][] = vis[c[cur]][] = true;
dfs(cur + ,cnt + );
vis[d[cur]][] = vis[c[cur]][] = false;
}
}
bool cc[maxn][maxn];
int main(){
init();
while(~scanf("%d%d",&n,&m)){
ret = ;
memset(vis,false,sizeof vis);
memset(cc,false,sizeof cc);
for(int i = ; i < m; ++i){
scanf("%d%d",d+i,c+i);
if(cc[d[i]][c[i]]){
--i;
--m;
}else cc[d[i]][c[i]] = true;
}
dfs(,);
printf("%lld\n",ret);
}
return ;
}
ZOJ 3687 The Review Plan I的更多相关文章
- (转)ZOJ 3687 The Review Plan I(禁为排列)
The Review Plan I Time Limit: 5 Seconds Memory Limit: 65536 KB Michael takes the Discrete Mathe ...
- ZOJ 3687 The Review Plan I 容斥原理
一道纯粹的容斥原理题!!不过有一个trick,就是会出现重复的,害我WA了几次!! 代码: #include<iostream> #include<cstdio> #inclu ...
- The Review Plan I-禁位排列和容斥原理
The Review Plan I Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer ...
- ZOJ 3687
赤裸的带禁区的排列数,不过,难点在于如何用程序来写这个公式了.纠结了好久没想到,看了看别人的博客,用了DFS,实在妙极,比自己最初想用枚举的笨方法高明许多啊.\ http://blog.csdn.ne ...
- harukaの赛前日常
REMEMBER US. haruka是可爱的孩子. 如题,此博客用来记录我停课后的日常. Dear Diary 10.8 上午考试. T1,直接枚举每一个点最后一次被修改的情况.(100pts) T ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- PLSQL_性能优化系列19_Oracle Explain Plan解析计划通过Profile绑定
20150529 Created By BaoXinjian
- Setup SQL Server 2008 Maintenance Plan Email Notifications
一条龙作完,如何设置EXCHANGE的操作员邮件通知.. ~~~~ http://808techblog.com/2009/07/setup-sql-server-2008-maintena.html ...
- Quality in the Test Automation Review Process and Design Review Template
About this document Prerequisite knowledge/experience: Software Testing, Test Automation Applicable ...
随机推荐
- E20170623-ts
filter n. 滤波器; 滤光器; 滤色镜; [化] 过滤器; mass n. 大量,大多; 块,堆,团; [物理学] 质量; 弥撒曲; assignment n. 分给,分配; 任务, ...
- knockjs
用VS2012建立Web站点有个新惊喜,默认加了KnockoutJS这个Javascript的MVVM模式的实现库,方便Web前端的开发 官方站点 √主页: http://www.knockoutj ...
- openpyxl python操作Excel表格,
这里openpyxl只支持xlsx格式的Excel,openpyxl使用起来会更方便一些,所以如果只操作小流水线文件的话,那么可以优先选择openpyxl,如果要兼容xls的话,就使用xlrd/xlw ...
- Quartz在服务异常中断或者重启后,不执行之前漏掉的任务,重新运行下一次任务
Quartz默认重启后会执行之前的任务,所以如果不想执行之前漏掉的任务,需要设置一下两个地方: CRON triggers CronTrigger trigger = TriggerBuilder.n ...
- Java系列学习(零)-写在前面的话
1.为什么写这套笔记 理由一:因为需求,所以学习,然后就要记笔记 理由二:同时学几种相似的语言,怕搞混,所以写 2.笔记修改日志
- jdk11安装没有jre文件夹
原因:jdk11安装之后是没有jre的 如果需要jre,需要到jdk目录下面去 打开命令窗口,然后执行如下命令: bin\jlink.exe --module-path jmods --a ...
- 精美对UI设计界面赏析
最美的UI设计界面赏析 . 喜欢就关注我吧
- 在mac上快捷找到nodejs的安装路径
打开控制台输入 which node ,得到的输出结果就是node安装路径
- echarts通过ajax请求展示多叉树
背景:在sqlserver使用过程中经常由于各种原因会出现阻塞,并发数较高,很难肉眼看出那个session阻塞了其他process,通过sql查询出根源也需要大量的重复操作才能够找到. 因此就有这方面 ...
- SQL基本操作——存储过程
存储过程类似于C#中的方法. --创建存储过程 create proc usp_TwoNumberAdd @num1 int, @num2 int as begin select @num1+@num ...