(转)ZOJ 3687 The Review Plan I(禁为排列)
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≤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
转: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(禁为排列)的更多相关文章
- ZOJ 3687 The Review Plan I
The Review Plan I Time Limit: 5000ms Memory Limit: 65536KB This problem will be judged on ZJU. Origi ...
- ZOJ 3687 The Review Plan I 容斥原理
一道纯粹的容斥原理题!!不过有一个trick,就是会出现重复的,害我WA了几次!! 代码: #include<iostream> #include<cstdio> #inclu ...
- The Review Plan I-禁位排列和容斥原理
The Review Plan I Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer ...
- ZOJ 3687
赤裸的带禁区的排列数,不过,难点在于如何用程序来写这个公式了.纠结了好久没想到,看了看别人的博客,用了DFS,实在妙极,比自己最初想用枚举的笨方法高明许多啊.\ http://blog.csdn.ne ...
- ZOJ 3874 Permutation Graph (分治NTT优化DP)
题面:vjudge传送门 ZOJ传送门 题目大意:给你一个排列,如果两个数构成了逆序对,就在他们之间连一条无向边,这样很多数会构成一个联通块.现在给出联通块内点的编号,求所有可能的排列数 推来推去容易 ...
- harukaの赛前日常
REMEMBER US. haruka是可爱的孩子. 如题,此博客用来记录我停课后的日常. Dear Diary 10.8 上午考试. T1,直接枚举每一个点最后一次被修改的情况.(100pts) T ...
- 组合数学:容斥原理(HDU1976)
●容斥原理所研究的问题是与若干有限集的交.并或差有关的计数. ●在实际中, 有时要计算具有某种性质的元素个数. 例: 某单位举办一个外语培训班, 开设英语, 法语两门课.设U为该单位所有人集合, A, ...
- JMeter 二:执行顺序 & 支持的协议
执行顺序 参考:http://jmeter.apache.org/usermanual/test_plan.html#executionorder 不同种类元素之间,执行顺序如下: Configura ...
- 【译】N 皇后问题 – 构造法原理与证明 时间复杂度O(1)
[原] E.J.Hoffman; J.C.Loessi; R.C.Moore The Johns Hopkins University Applied Physics Laboratory *[译]* ...
随机推荐
- Java宝典(一)
-switch语句能作用在byte上,能否作用在long上,能否作用在String上? -在switch(expr1)中,expr1只能是一个整数表达式或者枚举常量,整数表达式可以是int基本类型或I ...
- 你被adblock坑过吗?
最近上线一个新版本,需要在导航增加一个app的下载入口(一个图片链接),然后经过了正常的原型图.设计.切图.上线的过程,一切都是那么顺利.上线之后,像往常一下会让产品进行确认,所有的调整和优化 ...
- sem_timedwait的用法
#include <semaphore.h> int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout); Link ...
- phpcms 去掉默认自动获取关键词、自动提取第一张图片?
进入后台,内容--模型管理--管理模型,选择文章模型的字段管理,选择第13项内容--修改,然后把字段提示代码中的2个checked去掉就行了. <label><input name= ...
- Android开源库集锦
一.兼容类库 ActionBarSherlock : Action Bar是Android 3.0后才开始支持的,ActionBarSherlock是让Action Bar功能支持2.X后的所有平台, ...
- Java的IO以及线程练习
文件的IO操作: 字节流: 输入字节流: InputStream 所有输入字节流的基类,抽象类. FileInputStream 读取文件的输入字节流. BufferedInputStream ...
- poj1410
简单题,注意是实心矩形 #include <iostream> #include <math.h> #include <iomanip> #define eps 1 ...
- [CSS] CSS Transitions: Delays and Multiple Properties
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery- ...
- .NET基础拾遗(1)类型语法基础和内存管理基础2
二.内存管理和垃圾回收 2.1 .NET中栈和堆 每一个.NET应用程序最终都会运行在一个OS进程中,假设这个OS的传统的32位系统,那么每个.NET应用程序都可以拥有一个4GB的虚拟内存..NET会 ...
- MySql命令——游标
1.游标的概念 有时,需要在检索出来的行中前进或后退一行或多行.这就是使用游标的原因.游标(cursor)是一个存储在 MySql 服务器上的数据库查询,它不是一条 select 语句,而是被该语句检 ...