The Review Plan I

Time Limit: 5000ms
Case Time Limit: 5000ms
Memory Limit: 65536KB
 
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
#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-禁位排列和容斥原理的更多相关文章

  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

    The Review Plan I Time Limit: 5000ms Memory Limit: 65536KB This problem will be judged on ZJU. Origi ...

  3. [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)

    [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...

  4. [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)

    [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...

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

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

  6. BZOJ 4517: [Sdoi2016]排列计数 [容斥原理]

    4517: [Sdoi2016]排列计数 题意:多组询问,n的全排列中恰好m个不是错排的有多少个 容斥原理强行推♂倒她 $恰好m个不是错排 $ \[ =\ \ge m个不是错排 - \ge m+1个不 ...

  7. 组合数学:容斥原理(HDU1976)

    ●容斥原理所研究的问题是与若干有限集的交.并或差有关的计数. ●在实际中, 有时要计算具有某种性质的元素个数. 例: 某单位举办一个外语培训班, 开设英语, 法语两门课.设U为该单位所有人集合, A, ...

  8. 【译】N 皇后问题 – 构造法原理与证明 时间复杂度O(1)

    [原] E.J.Hoffman; J.C.Loessi; R.C.Moore The Johns Hopkins University Applied Physics Laboratory *[译]* ...

  9. N皇后问题(位运算实现)

    本文参考Matrix67的位运算相关的博文. 顺道列出Matrix67的位运算及其使用技巧 (一) (二) (三) (四),很不错的文章,非常值得一看. 主要就其中的N皇后问题,给出C++位运算实现版 ...

随机推荐

  1. Canvas中图片翻转的应用

    很多时候拿到的素材都是单方向的,需要将其手动翻转来达到需求,比如下面这张图片: 它是朝右边方向的,但还需要一张朝左边方向的,于是不得不打开PS将其翻转然后做成雪碧图.如果只是一张图片还好说,但通常情况 ...

  2. SpringMvc aop before

    1.config.xml配置文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans ...

  3. 非spring托管的类使用spring脱管的类。

    import org.springframework.beans.BeansException; import org.springframework.context.ApplicationConte ...

  4. Selenium学习(三)Selenium总是崩溃的解决办法

    在使用selenium打开浏览器总是崩溃,最近查资料获得可行的解决办法: import sys from selenium import webdriver p = __import__('selen ...

  5. 如何使用CocoaPods安装使用及配置私有库以及管理依赖库 【原创】

    CocoaPods是什么 在iOS开发中势必会用到一些第三方依赖库,比如大家都熟悉的ASIHttpRequest.AFNetworking.JSONKit等.使用这些第三方类库能极大的方便项目的开发, ...

  6. mongodb distinct去重

    MongoDB的destinct命令是获取特定字段中不同值列表.该命令适用于普通字段,数组字段和数组内嵌文档. mongodb的distinct的语句: db.users.distinct('last ...

  7. IdentityServer4 + SignalR Core +RabbitMQ 构建web即时通讯(一)

    IdentityServer4 + SignalR Core +RabbitMQ 构建web即时通讯 前言 .net core 2.1已经正式发布了,signalr core1.0随之发布,是时候写个 ...

  8. ASP.NET动态网站制作(5)-- 标签语义化及知识补充

    前言:这节课主要是讲标签语义化及一些知识点的补充 内容:参考老师的博文:http://www.cnblogs.com/ruanmou/p/4821894.html

  9. iOS程序自动检测更新的实现

      本文转载至 http://blog.csdn.net/davidsph/article/details/8931718 App Store自动更新itunes     之前项目需要用到app自动更 ...

  10. iphone开发之获取网卡的MAC地址和IP地址

    本文转载至 http://blog.csdn.net/arthurchenjs/article/details/6358489 这是获取网卡的硬件地址的代码,如果无法编译通过,记得把下面的这几个头文件 ...