zoukankan      html  css  js  c++  java
  • The Review Plan I 禁为排列

    Description

    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
    ***********************************************************************************************************************************************************
    ***********************************************************************************************************************************************************
     1 #include<iostream>
     2 #include<string>
     3 #include<cstring>
     4 #include<queue>
     5 #include<cstdio>
     6 #include<cmath>
     7 #define  LL long long
     8 #define  MOD  55566677
     9 using namespace std;
    10 LL  f[1001];
    11 int vis1[1001],vis2[1001],ban[1001][1001];
    12 int a[1001][2];
    13 int n,m;
    14 LL res;
    15 void init()
    16 {
    17     f[0]=1;
    18     for(LL i=1;i<=60;i++)
    19      f[i]=(f[i-1]*i)%MOD;
    20 }
    21 void dfs(int i,int num)
    22 {
    23     if(i>m)
    24     {
    25         if(num&1)
    26         {
    27             res=((res-f[n-num])%MOD+MOD)%MOD;
    28         }
    29         else
    30           res=(res+f[n-num])%MOD;
    31         return;
    32     }
    33     dfs(i+1,num);
    34     if((!vis1[a[i][0]])&&(!vis2[a[i][1]]))
    35     {
    36         vis1[a[i][0]]=vis2[a[i][1]]=1;
    37         dfs(i+1,num+1);
    38         vis1[a[i][0]]=vis2[a[i][1]]=0;
    39     }
    40 }
    41 
    42 int main()
    43 {
    44     init();
    45     int i,j,k;
    46    while(scanf("%d %d",&n,&m)!=EOF)
    47    {
    48        memset(ban,0,sizeof(ban));
    49        memset(vis1,0,sizeof(vis1));
    50        memset(vis2,0,sizeof(vis2));
    51        for(i=1;i<=m;i++)
    52        {
    53            scanf("%d%d",&a[i][0],&a[i][1]);
    54            if(ban[a[i][0]][a[i][1]])
    55            {
    56                i--;
    57                m--;
    58            }
    59            else
    60             ban[a[i][0]][a[i][1]]=1;
    61        }
    62        res=0;
    63        dfs(1,0);
    64        res=(res%MOD+MOD)%MOD;
    65        printf("%lld
    ",res);
    66    }
    67    return 0;
    68 }
    View Code
  • 相关阅读:
    阿里云服务器购买后的配置指南
    第一阶段总结
    RDD的checkpoint机制和键值对RDD数据分区
    广播变量与累加器
    Spark的监控
    Spark和MR的区别
    hadoop离线项目处理流程
    Flume(一)
    Sparkcore高级应用3
    SparkCore高级应用2(Spark on yarn)
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3442267.html
Copyright © 2011-2022 走看看