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

Author

LI, Huang
 
解题:容斥原理+搜索
 #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的更多相关文章

  1. (转)ZOJ 3687 The Review Plan I(禁为排列)

    The Review Plan I Time Limit: 5 Seconds      Memory Limit: 65536 KB Michael takes the Discrete Mathe ...

  2. ZOJ 3687 The Review Plan I 容斥原理

    一道纯粹的容斥原理题!!不过有一个trick,就是会出现重复的,害我WA了几次!! 代码: #include<iostream> #include<cstdio> #inclu ...

  3. The Review Plan I-禁位排列和容斥原理

    The Review Plan I Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB   64-bit integer ...

  4. ZOJ 3687

    赤裸的带禁区的排列数,不过,难点在于如何用程序来写这个公式了.纠结了好久没想到,看了看别人的博客,用了DFS,实在妙极,比自己最初想用枚举的笨方法高明许多啊.\ http://blog.csdn.ne ...

  5. harukaの赛前日常

    REMEMBER US. haruka是可爱的孩子. 如题,此博客用来记录我停课后的日常. Dear Diary 10.8 上午考试. T1,直接枚举每一个点最后一次被修改的情况.(100pts) T ...

  6. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  7. PLSQL_性能优化系列19_Oracle Explain Plan解析计划通过Profile绑定

    20150529 Created By BaoXinjian

  8. Setup SQL Server 2008 Maintenance Plan Email Notifications

    一条龙作完,如何设置EXCHANGE的操作员邮件通知.. ~~~~ http://808techblog.com/2009/07/setup-sql-server-2008-maintena.html ...

  9. Quality in the Test Automation Review Process and Design Review Template

    About this document Prerequisite knowledge/experience: Software Testing, Test Automation Applicable ...

随机推荐

  1. HTML5浏览器嵌入窗口程序解决方案

    浏览器嵌入窗口程序一直以来就是WEB应用程序的首选方案,这种方案只需要实现一个主窗口,并提供一些接口供脚本调用,内部的界面和逻辑处理全部用html,css,javascript去实现.我最早看到的相关 ...

  2. Set的非重复判断是根据什么判断的

    HashSet 首先来看下HashSet的add()这个方法的源代码: public boolean add(E e) { return map.put(e, PRESENT)==null; } 由此 ...

  3. bzoj 2276 [ Poi 2011 ] Temperature —— 单调队列

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2276 维护 l 递减的单调队列,队头的 l > 当前的 r 就出队,因为不能是连续一段 ...

  4. bzoj1833

    http://www.lydsy.com/JudgeOnline/problem.php?id=1833 2.5个小时就花在这上面了... 水到200题了...然并卵,天天做水题有什么前途... #i ...

  5. 特征选择--->卡方选择器

    特征选择(Feature Selection)指的是在特征向量中选择出那些“优秀”的特征,组成新的.更“精简”的特征向量的过程.它在高维数据分析中十分常用,可以剔除掉“冗余”和“无关”的特征,提升学习 ...

  6. PCB 加投率计算实现基本原理--K最近邻算法(KNN)

    PCB行业中,客户订购5000pcs,在投料时不会直接投5000pcs,因为实际在生产过程不可避免的造成PCB报废, 所以在生产前需计划多投一定比例的板板, 例:订单 量是5000pcs,加投3%,那 ...

  7. ansible剧本

    yaml简介 YAML是"YAML Ain't a Markup Language"(YAML不是一种置标语言)的递归缩写,早先YAML的意思其实是:"Yet Anoth ...

  8. UNIX环境高级编程--4

    函数stat fstat fstatat 和 lstat stat函数使用最多的地方可能就是ls -l 命令,用其可以获得有关一个文件的所有信息. 文件类型: (1)普通文件 (2)目录文件 (3)块 ...

  9. 去除IOS苹果手机自带按钮样式的问题~

    input[type="button"], input[type="submit"], input[type="reset"] { -web ...

  10. Android之Glide获取图片Path和Glide获取图片Bitmap

    今天主要研究了Glide获取图片Path.Bitmap用法,相信也困扰了大家很久,我在网上也找了很久,基本没有,后来研究了下,也参考了下api文档,总结了以下几个方式: 1. 获取Bitmap: 1) ...