(转)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 *[译]* ...
随机推荐
- Zoj3332-Strange Country II(有向竞赛图)
You want to visit a strange country. There are n cities in the country. Cities are numbered from 1 t ...
- extjs两个tbar问题
版本:extjs3.4 接触过extjs的同志们都知道每个panel都有一个tbar(top bar 上面工具栏) ,bbar(bottom bar 底部工具栏) 大家做查询页面,一 ...
- IOS UIImage 模糊
#import <UIKit/UIKit.h> #import <Accelerate/Accelerate.h> #import <QuartzCore/QuartzC ...
- 基础总结篇之五:BroadcastReceiver应用详解
問渠那得清如許?為有源頭活水來.南宋.朱熹<觀書有感> 据说程序员是最爱学习的群体,IT男都知道,这个行业日新月异,必须不断地学习新知识,不断地为自己注入新鲜的血液,才能使自己跟上技术的步 ...
- 炉石传说__multiset
炉石传说 Problem Description GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说.但是传统的炉石传说对于刚入门的GG学长来说有点复杂,所以他决定自己开发一个简化版 ...
- 解决getJdbcTemplate往oracle数据库中插入数据返回主键出错问题
我们使用Spring中的JdbcDaoSupport往Mysql中插入数据并返回主键代码,我们使用的mysql数据库,主键在数据库中设置为自增长:该类继承自JdbcDaoSupport,所以能直接使用 ...
- [Git] set-upstream
When you want to push your local branch to remote branch, for the first push: git push --set-upstrea ...
- BZOJ 2648/2716(SJY把件-KD_Tree)[Template:KD_Tree]
2648: SJY把件 Time Limit: 20 Sec Memory Limit: 128 MB Submit: 1180 Solved: 391 [id=2648" style= ...
- iOS textfield限制长度,中文占2字符,英文占1字符
之前遇到一种情况,限制textfield长度,并且要适配多语言,做到,例如中文占2字符,英文占1字符,还有考虑其他语言,网上找了很多方法,不太合适,最后结合网上的方案,修改出了还比较适用. 首先,增加 ...
- 细讲encodeURI和encodeURIComponent以及escape的区别与应用
首先,我们都知道这三个东西都是用来编码的 先来说encodeURI()和encodeURIComponent() 这两个是在转换url时候用来编码解码用的. 有编码就会有解码, 解码就是decodeU ...