The Review Plan I-禁位排列和容斥原理
The Review Plan I
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
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
#define mod 55566677
long long day[],zhang[],c[],i,ss,m,n,gx[][];
struct PP
{
int d,z;
}chi[];
int rc(int x,int y)
{
if(x>=m)
{
if(y&)ss-=c[n-y];
else ss+=c[n-y];
ss%=mod;
ss=(ss+mod)%mod;
return ;
}
rc(x+,y);
if(day[chi[x].d]==&&zhang[chi[x].z]==)
{
day[chi[x].d]=;zhang[chi[x].z]=;
rc(x+,y+);
day[chi[x].d]=;zhang[chi[x].z]=;
}
}
int main()
{
c[]=;c[]=;
for(i=;i<=;i++)c[i]=(c[i-]*i)%mod;
while(cin>>n>>m&&n+m!=)
{
ss=;
memset(day,,sizeof(day));
memset(zhang,,sizeof(zhang));
memset(gx,,sizeof(gx));
for(i=;i<m;i++)
{
cin>>chi[i].d>>chi[i].z;
if(gx[chi[i].d][chi[i].z]==)gx[chi[i].d][chi[i].z]=;
else {m--;i--;}
}
rc(,);
ss=(ss+mod)%mod;
cout<<ss<<endl;
}
return ;
}
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
The Review Plan I Time Limit: 5000ms Memory Limit: 65536KB This problem will be judged on ZJU. Origi ...
- [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)
[Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...
- [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)
[Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...
- ZOJ 3687 The Review Plan I 容斥原理
一道纯粹的容斥原理题!!不过有一个trick,就是会出现重复的,害我WA了几次!! 代码: #include<iostream> #include<cstdio> #inclu ...
- BZOJ 4517: [Sdoi2016]排列计数 [容斥原理]
4517: [Sdoi2016]排列计数 题意:多组询问,n的全排列中恰好m个不是错排的有多少个 容斥原理强行推♂倒她 $恰好m个不是错排 $ \[ =\ \ge m个不是错排 - \ge m+1个不 ...
- 组合数学:容斥原理(HDU1976)
●容斥原理所研究的问题是与若干有限集的交.并或差有关的计数. ●在实际中, 有时要计算具有某种性质的元素个数. 例: 某单位举办一个外语培训班, 开设英语, 法语两门课.设U为该单位所有人集合, A, ...
- 【译】N 皇后问题 – 构造法原理与证明 时间复杂度O(1)
[原] E.J.Hoffman; J.C.Loessi; R.C.Moore The Johns Hopkins University Applied Physics Laboratory *[译]* ...
- N皇后问题(位运算实现)
本文参考Matrix67的位运算相关的博文. 顺道列出Matrix67的位运算及其使用技巧 (一) (二) (三) (四),很不错的文章,非常值得一看. 主要就其中的N皇后问题,给出C++位运算实现版 ...
随机推荐
- 四、Silverlight中使用MVVM(四)——演练
本来打算用MVVM实现CRUD操作的,这方面例子网上资源还挺多的,毕竟CRUD算是基本功了,因为最近已经开始学习Cailburn框架了,感觉时间 挺紧的,这篇就实现其中的更新操作吧. 功能很明确,当我 ...
- 调整图像的尺寸 - cvResize() 函数实现
前言 有时会碰到一张图片太大了,想将它缩小.本文将讲解一个很好用的函数解决这个问题. 图像尺寸调整函数 cvResize() // 图像尺寸调整函数 void Resize ( const CvArr ...
- 【转】php和java之间rsa加密互通
以下是php封装好的类,引入即可使用 <?php /** * 作者:pjp * 邮箱:vippjp@163.com */ class RSA{ private $privateKey='';// ...
- _THROW 何解?
在看/usr/include/........中.h头文件对函数接口的定义时,总是能看到在函数结尾加一个_THROW,一时不明白这是什么意思,而且对于有些POSIX和ISO C不承认或未明确的定义的函 ...
- Windows操作系统远程Linux服务器传输文件方法(以EasyDSS云平台、EasyNVR上传部署为例)
本文转自博客:https://blog.csdn.net/black_3717/article/details/79769406 问题背景: 之前给客户部署我们一款EasyDSS云平台(配合EasyN ...
- segnet 编译与测试
segnet 编译与测试参考:http://sunxg13.github.io/2015/09/10/caffe/http://m.blog.csdn.net/lemianli/article/det ...
- imagecopyresampled()改变图片大小后质量要比imagecopyresized()高。
php程序中改变图片大小的函数大多数人都想到用imagecopyresized(),不过经过测试比较发现,使用imagecopyresampled()改变的图片质量更高. 下面我们来看看两者的比较结果 ...
- 20170326 ABAP调用外部webservice实例
调用外部webservice 使用Tcode: SICF SPROXSET 设置创建proxy 的权限 SE80 SOAMANAGER 一.目的:调用外部SRM系统的 webservice: ...
- SD相关的表
[转] 一.客户主数据基本数据放在KNA1里:公司代码放在KNB1里:销售视图放在KNVV里:合作伙伴放在KNVP里:二.信用主数据KNKK里有信贷限额.应收总额.特别往来:S066里是未清订单值:S ...
- 使用qt+ros调用摄像头遇到的问题
当使用摄像头遇到如下问题:[usb_cam-1] process has died [pid 12288, exit code 127, cmd /opt/ros/indigo/lib/usb_cam ...