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
  • 相关阅读:
    ue4同c#通信时的中文乱码问题
    ue4 fstring 和std::string互转
    LinqToExcel 简洁与优美开源库
    虚幻UE4的后处理特效介绍 http://www.52vr.com/thread-31215-1-1.html
    为什么你应该使用OpenGL而不是DirectX?
    会写代码是你创业路上的包袱
    (转载)怎样解决SQL Server内存不断增加问题
    UE4 Pak 相关知识总结
    淘宝运营实战操作大纲
    淘宝运营
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4819886.html
Copyright © 2011-2022 走看看