zoukankan      html  css  js  c++  java
  • ZOJ 3687 The Review Plan I

    The Review Plan I

    Time Limit: 5000ms
    Memory Limit: 65536KB
    This problem will be judged on ZJU. Original ID: 3687
    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
    
     

    Source

    Author

    LI, Huang
     
    解题:容斥原理+搜索
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 const int maxn = 51;
     5 const LL mod = 55566677;
     6 LL F[maxn] = {1};
     7 void init(){
     8     for(int i = 1; i < maxn; ++i)
     9         F[i] = F[i-1]*i%mod;
    10 }
    11 LL ret = 0;
    12 bool vis[maxn][2];
    13 int d[maxn],c[maxn],n,m;
    14 void dfs(int cur,int cnt){
    15     if(cur >= m){
    16         if(cnt&1) ret = (ret - F[n - cnt] + mod)%mod;
    17         else ret = (ret + F[n - cnt])%mod;
    18         return;
    19     }
    20     dfs(cur+1,cnt);
    21     if(!vis[d[cur]][0] && !vis[c[cur]][1]){
    22         vis[d[cur]][0] = vis[c[cur]][1] = true;
    23         dfs(cur + 1,cnt + 1);
    24         vis[d[cur]][0] = vis[c[cur]][1] = false;
    25     }
    26 }
    27 bool cc[maxn][maxn];
    28 int main(){
    29     init();
    30     while(~scanf("%d%d",&n,&m)){
    31         ret = 0;
    32         memset(vis,false,sizeof vis);
    33         memset(cc,false,sizeof cc);
    34         for(int i = 0; i < m; ++i){
    35             scanf("%d%d",d+i,c+i);
    36             if(cc[d[i]][c[i]]){
    37                 --i;
    38                 --m;
    39             }else cc[d[i]][c[i]] = true;
    40         }
    41         dfs(0,0);
    42         printf("%lld
    ",ret);
    43     }
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    Python学习第75天(js历史和引入,模块复习)
    Python学习第74天(抽屉习题笔记)
    Python学习第73天(shelve模块、习题练习)
    Js查漏补缺02-各种数据类型
    Js查漏补缺01-js学习笔记
    开篇
    小小python欢乐多
    阅读笔记09 个人对于三年来软件工程的一点心得
    14周周博客
    软件杯第二阶段
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4819886.html
Copyright © 2011-2022 走看看