The Review Plan I-禁位排列和容斥原理

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[55],zhang[55],c[55],i,ss,m,n,gx[55][55];
struct PP
{
    int d,z;
}chi[55];
int rc(int x,int y)
{
    if(x>=m)
    {
        if(y&1)ss-=c[n-y];
        else ss+=c[n-y];
        ss%=mod;
        ss=(ss+mod)%mod;
        return 0;
    }
    rc(x+1,y);
    if(day[chi[x].d]==0&&zhang[chi[x].z]==0)
    {
        day[chi[x].d]=1;zhang[chi[x].z]=1;
        rc(x+1,y+1);
        day[chi[x].d]=0;zhang[chi[x].z]=0;
    }
}
int main()
{
    c[1]=1;c[0]=1;
    for(i=2;i<=50;i++)c[i]=(c[i-1]*i)%mod;
    while(cin>>n>>m&&n+m!=0)
    {
        ss=0;
        memset(day,0,sizeof(day));
        memset(zhang,0,sizeof(zhang));
        memset(gx,0,sizeof(gx));
        for(i=0;i<m;i++)
        {
            cin>>chi[i].d>>chi[i].z;
            if(gx[chi[i].d][chi[i].z]==0)gx[chi[i].d][chi[i].z]=1;
            else {m--;i--;}
        }
        rc(0,0);
        ss=(ss+mod)%mod;
        cout<<ss<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/lveternal/p/3420241.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值