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 ...
 
随机推荐
- 读取Excel文件到DataTable中
			
private static string[] GetExcelSheetNames(OleDbConnection conn) { DataTable dtbSh ...
 - Scaffold-DbContext-EFCore DB First
			
在使用 Scaffold-DbContext迁移数据库的时候会遇到两个问题. 一.文件已存在,其实报错很明显,增加 -force即可. 二.大小写转换,不和数据库一样了,如果要保持和数据库一致.增加 ...
 - ios-判断手机上是否安装了某个App
			
方法一 1.获取手机中安装的所有App 1.1.runtime中的方法,所以要导入 #include <objc/runtime.h> 1.2.在 AppDel ...
 - 【BZOJ1939】[Croatian2010] Zuma(动态规划)
			
题目: BZOJ1939(权限题) 分析: 这题很容易看出是DP,但是状态和转移都不是很好想-- 用\(dp[l][r][c]\)表示在\(l\)前面已经新加了\(c\)个和\(l\)一样的弹子时,使 ...
 - [转]Linux命令之iconv
			
转自:http://lorna8023.blog.51cto.com/777608/420313 用途说明 iconv命令是用来转换文件的编码方式的(Convert encoding of given ...
 - JS高级——面向对象方式解决歌曲管理问题
			
需要注意的问题: 1.其他模块若是使用构造函数MP3创建对象,唯一不同的就是他们传入的音乐库是不一样的,所以构造函数中存在一个songList属性,其他一样的就被添加到了构造函数的原型对象之中 2.原 ...
 - 转:selenium自动化脚本错误总结
			
https://blog.csdn.net/zxy987872674/article/details/53141118
 - (原创)HyperPacer使用技巧之集合点设置
			
版权声明:本文为原创文章,转载请先联系并标明出处 性能测试中,我们可以模拟最真实的用户操作来建立性能模型,但是这种模拟是相对的.譬如12306网站春运开始后每一天都是高峰,这种高负载情况会持续一至两个 ...
 - 安装nodejs6.9x以后,原来在nodejs4.2.x中运行正常的ionic项目出现问题的解决
			
安装nodejs6.9x以后,原来在nodejs4.2.x中运行正常的程序出现的问题.看错误信息,由于NodeJs版本升级导致的. 到提示的目录下运行:npm rebuild node-sass -g ...
 - Twisted web开发教程
			
最近在网上看到一篇twisted web开发文章,将它实践了一下,twisted 提供基本的url路由 和 控制器,模板与模型需要外部扩展 1.目录浏览 2.get请求 3.url路由 4.接受带参数 ...