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≤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


#include
#include
#include
#include
#include
#include
#include
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)
        {
            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<endl;
    }
    return 0;
}

 

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

你可能感兴趣的:(java)