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
  • 相关阅读:
    EVIOCGNAME:Get Device Name
    Andriod Sensor HAL 分析
    通知内核你的设备 不支持llseek, 通过在你的 open 方法中调用nonseekable_open
    linux Gsensor驱动(bma250为例子)
    Linux输入子系统:输入设备编程指南 -- input-programming.txt
    Android UEventObserver 使用
    android switch模块
    linux里的驱动接口
    input subsystem 函数解释
    2.6 内核中的计时器 小结
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3442267.html
Copyright © 2011-2022 走看看