The Review Plan I


Time Limit: 5 Seconds      Memory Limit: 65536 KB

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
转:http://blog.csdn.net/hlmfjkqaz/article/details/11037821
题意:有n个位置,m个东西,第C个东西不能放在第D个位置(禁位)。
收获:了解了:禁位排列和错位排列。http://wenku.baidu.com/link?url=H20jYGza0kMrRgxev671hFCSSR-YS0VxdSz9pu1u4cUPpCj-8C73lgnLQWZkApEvVBxuzVuk9t7ArwwvzC_dZMettS0CvBcvxv4GPybU2VS
#include<iostream>
#include<cstdio>
#include<string.h>
#include<math.h>
using namespace std;
typedef long long LL;
#define MOD 55566677
#define N 55
LL f[N],res;
int n,m,vis1[N],vis2[N],a[N][N],ban[N][N];
void inint()
{
f[]=;
for(int i=; i<N; i++)
f[i]=(f[i-]*i)%MOD;
}
void dfs(int i,int num) //第i个禁位,选num个禁位
{
if(i>m)
{
if(num&) res=((res-f[n-num])%MOD+MOD)%MOD;
else res=(res+f[n-num])%MOD;
return;
}
dfs(i+,num); //第i个禁位不选
if((!vis1[a[i][]])&&(!vis2[a[i][]])) //选第i个禁位
{
vis1[a[i][]]=vis2[a[i][]]=;
dfs(i+,num+);
vis1[a[i][]]=vis2[a[i][]]=;
}
} int main()
{
int i,j,d,c;
inint();
while(~scanf("%d%d",&n,&m))
{
memset(vis1,,sizeof(vis1));
memset(vis2,,sizeof(vis2));
memset(ban,,sizeof(ban));
for(i=; i<=m; i++)
{
scanf("%d%d",&a[i][],&a[i][]);
if(ban[a[i][]][a[i][]])
{
i--;
m--;
}
else ban[a[i][]][a[i][]]=;
}
res=;
dfs(,);
res=(res%MOD+MOD)%MOD;
printf("%lld\n",res);
}
return ;
}

(转)ZOJ 3687 The Review Plan I(禁为排列)的更多相关文章

  1. ZOJ 3687 The Review Plan I

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

  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. ZOJ 3874 Permutation Graph (分治NTT优化DP)

    题面:vjudge传送门 ZOJ传送门 题目大意:给你一个排列,如果两个数构成了逆序对,就在他们之间连一条无向边,这样很多数会构成一个联通块.现在给出联通块内点的编号,求所有可能的排列数 推来推去容易 ...

  6. harukaの赛前日常

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

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

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

  8. JMeter 二:执行顺序 & 支持的协议

    执行顺序 参考:http://jmeter.apache.org/usermanual/test_plan.html#executionorder 不同种类元素之间,执行顺序如下: Configura ...

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

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

随机推荐

  1. Linux中使用mysqldump对MySQL数据库进行定时备份

    #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH expo ...

  2. POJ 2010 Moo University - Financial Aid 优先队列

    题意:给你c头牛,并给出每头牛的分数和花费,要求你找出其中n(n为奇数)头牛,并使这n头牛的分数的中位数尽可能大,同时这n头牛的总花费不能超过f,否则输出-1. 思路:首先对n头牛按分数进行排序,然后 ...

  3. py练习

    功能类似pop def myPop():    l=[]    a=raw_input('a:')    for i in a:        l.append(i)    l.pop()    pr ...

  4. 如何在cmd窗口启动Tomcat

    平时,一般使用tomcat/bin/startup.bat目录在windows环境启动Tomcat,或者使用IDE配置后启动. 下面来简单介绍下如果在cmd窗口直接输入命令启动Tomcat: 1.将t ...

  5. java与.net比较学习系列(7) 属性

    文章摘自:http://www.cnblogs.com/mcgrady/p/3411405.html 说起属性,实际上java中没有属性这个概念,只有字段和方法,但是可以通过私有字段和声明get,se ...

  6. java实现点名,并记录被点次数

    java实现点名,并记录被点次数 import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStrea ...

  7. .net 导出

    public void CreateExcel(DataTable dt, string fileName) { HttpResponse resp = System.Web.HttpContext. ...

  8. 1203.1——条件语句 之 if语句

    用if语句可以构成分支结构.它根据给定的条件进行判断,以决定执行某个分支程序段.C语言的if语句有三种基本形式. 语句的三种形式 1) 第一种形式为基本形式:if        if(表达式) 语句其 ...

  9. java静态成员的初始化过程

    public class Price{ final static Price INSTANCE = new Price(2.8); static double initPrice = 20; doub ...

  10. 写一个Windows上的守护进程(5)文件系统重定向

    写一个Windows上的守护进程(5)文件系统重定向 在Windows上经常操作文件或注册表的同学可能知道,有"文件系统/注册表重定向"这么一回事.大致来说就是32位程序在64位的 ...