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. Bing Maps进阶系列四:路由功能服务(RouteService)

    Bing Maps进阶系列四:路由功能服务(RouteService) Bing Maps提供的路由功能服务(RouteService)可以实现多方位的计算地图上的路线指示,路径行程等功能,比如说实现 ...

  2. POJ Area of Simple Polygons 扫描线

    这个题lba等神犇说可以不用离散化,但是我就是要用. 题干: Description There are N, <= N <= , rectangles -D xy-plane. The ...

  3. http协议的MP4文件播放问题的分析

    现在手上有两个链接 (1) http://202.108.16.173/cctv/video/8C/35/EB/E8/8C35EBE84E7B483C8741CF9A60154993/gphone/4 ...

  4. Spark 操作Hive 流程

    1.ubuntu 装mysql 2.进入mysql: 3.mysql>create database hive (这个将来是存 你在Hive中建的数据库以及表的信息的(也就是元数据))mysql ...

  5. 手动安装jar包到Maven本地仓库

    接手别人的一个项目,Maven工程,导入后,某些jar包找不到,然后从同事那复制Maven本地仓库的文件夹到我的电脑,发现依旧找不到.问题大致总结为:本地maven仓库存在jar,但是依然报Missi ...

  6. Linux学习大纲

  7. js获取后台数据

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  8. js模拟复制

    现在浏览器种类也越来越多,诸如 IE.Firefox.Chrome.Safari等等,因此现在要实现一个js复制内容到剪贴板的小功能就不是一件那么容易的事了.   一.实现点击按钮,复制文本框中的的内 ...

  9. 个人微信二次开发API接口

    通过这个API接口可以做什么? 通过我们提供的API接口您可以开发: 工作手机(如:X创,X码,XX管家等) 微信群讲课软件(如:讲课X师,一起X堂等) 微信社群管理软件(如:小X管家,微X助手等) ...

  10. java,安卓之信息的输出

    Android中实现信息的输出 java一般的打印办法为System.out.println("");J2ME也是,在ide的控制台就可以看到效果. 但是android平台,Sys ...