(转)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 *[译]* ...
随机推荐
- 3Sum Smaller 解答
Question Given an array of n integers nums and a target, find the number of index triplets i, j, k w ...
- 脚本控制向Android模拟拨打电话,发送短信,定位设置功能
做行为触发的时候要向模拟器实现拨打电话,发送短信,定位设置的的功能,可以很方便通过telnet localhost 5554实现. 写个脚本很快的搞定了.网上资料很多,脚本的很少,也所积点德啦. 写 ...
- IO队列和IO调度
IO体系概览 先看看本文主题IO调度和IO队列处于整个IO体系的哪个位置,这个IO体系是非常重要的,了解IO体系我们可以对整个IO过程有个全面的认识.虽然一下两下并不清楚IO体系各个部分的细节,但是我 ...
- pyqt sender()学习
#!/usr/bin/python # -*- coding: utf-8 -*- # sender.py import sys from PyQt4 import QtGui, QtCore cla ...
- 强制IE浏览器或WebBrowser控件使用指定版本显示网页
自从装了IE10之后,就发现好些个网站显示都不是那么的正常,网站上有些功能竟然还会出现一些意想不到的BUG——本来就是针对IE开发的,现在IE下竟然用不起来了,让用户情何以堪?但是就为少量用户使用的系 ...
- jstl数字保留两位小数
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%><fmt:fo ...
- [springmvc+mybatis][关于这两个框架的学习,我想说]
关于学习笔记 在对java web有了一定的了解后,这两个框架没怎么写学习笔记了…毕竟项目驱动型…… 关于学习资料 强烈推荐传智播客的燕青讲解的 让我对这种培训班教育的资料刮目相看(不过还是千万别去这 ...
- easyui-window
<div id="win" class="easyui-window" title="My Window" style="w ...
- Http请求和响应报文基础知识
一 HTTP请求报文(http://en.wikipedia.org/wiki/List_of_HTTP_header_fields) 请求报文由三部分组成:请求行,请求头和请求体. 请求行:请求方法 ...
- Android 使用monkey自动测试
很简单的一个monkey使用流程: 首先创建一个monkey脚本test.txt,例如一个简单的反复测试拍照功能的脚本: # Start of Script type= user count= 49 ...