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
  • 相关阅读:
    Excel中substitute替换函数的使用方法
    如何在Excel中提取小数点后面的数字?
    提升单元测试体验的利器--Mockito使用总结
    SpringMVC项目读取不到外部CSS文件的解决办法及总结
    java8 Lambda表达式的新手上车指南(1)--基础语法和函数式接口
    Spring-data-redis操作redis知识总结
    优雅高效的MyBatis-Plus工具快速入门使用
    Thrift入门初探(2)--thrift基础知识详解
    Thrift入门初探--thrift安装及java入门实例
    spring事件驱动模型--观察者模式在spring中的应用
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4819886.html
Copyright © 2011-2022 走看看