UVa11806 Cheerleaders

容斥问题

考虑上下左右四个边界只满足其中1/2/3/4个边界有人的情况,可以用组合数算。

总共只有16种情况。

可以用容斥原理求解。

 1 /*by SilverN*/
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 #include<vector>
 8 using namespace std;
 9 const int mod=1000007;
10 const int mxn=510;
11 int read(){
12     int x=0,f=1;char ch=getchar();
13     while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
14     while(ch>=‘0‘ && ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
15     return x*f;
16 }
17 int n,m,k;
18 int c[mxn][mxn];
19 void init(){
20     for(int i=0;i<=500;i++){
21         c[i][0]=1;
22         for(int j=1;j<=i;j++)
23             c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
24     }
25     return;
26 }
27 int main(){
28     int i,j;
29     int T=read(),cas=0;
30     init();
31     while(T--){
32         n=read();m=read();k=read();
33         int ct,a,b;
34         int ans=0;
35         for(i=0;i<=15;i++){
36             ct=0;a=n;b=m;
37             if(i&1)a--,ct++;
38             if(i&2)b--,ct++;
39             if(i&4)a--,ct++;
40             if(i&8)b--,ct++;
41             if(ct&1)(ans-=c[a*b][k])%=mod;
42             else (ans+=c[a*b][k])%=mod;
43         }
44         printf("Case %d: %d\n",++cas,ans);
45     }
46     return 0;
47 }
时间: 2024-08-04 22:23:11

UVa11806 Cheerleaders的相关文章

《算法竞赛入门经典——训练指南》第二章题库

UVa特别题库 UVa网站专门为本书设立的分类题库配合,方便读者提交: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=442 注意,下面注有"extra"的习题并没有在书中出现,但在上面的特别题库中有,属于附加习题. 基础练习 (Basic Problems) UVa11388 GCD LCM UVa11889 Benefit UVa10943 How do y

数学模型

Catalan 卡特兰数 - 计数的映射方法的伟大胜利 [AHOI2012]树屋阶梯 鸡蛋饼 [SCOI2010]生成字符串 Stirling 斯特林数 容斥 容斥原理(翻译) UVA10325 The Lottery(状压+容斥) UVA11806 Cheerleaders SP4191 MSKYCODE - Sky Code [CQOI2015]选数(容斥+递推) [SCOI2010]幸运数字 莫比乌斯反演与筛法 \[g(n)=\sum_{d|n}f(d)\] \[f(n)=\sum_{d|

UVA - 11806 - Cheerleaders (递推)

UVA - 11806 Cheerleaders Time Limit: 2000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description C Cheerleaders In most professional sporting events, cheerleaders play a major role in entertaining the spectators. Their roles a

【递推】【组合数】【容斥原理】UVA - 11806 - Cheerleaders

http://www.cnblogs.com/khbcsu/p/4245943.html 本题如果直接枚举的话难度很大并且会无从下手.那么我们是否可以采取逆向思考的方法来解决问题呢?我们可以用总的情况把不符合要求的减掉就行了. 首先我们如果不考虑任何约束条件,我们可以得出如下结论:                                                                       下载我们假定第一行不站拉拉队员的所有的站立方法有A种.最后一行不站拉拉队员的

uva11806(容斥原理)

11806 - Cheerleaders Time limit: 2.000 seconds In most professional sporting events, cheerleaders play a major role in entertaining the spectators. Their roles are substantial during breaks and prior to start of play. The world cup soccer is no excep

uva 11806 - Cheerleaders(容斥原理)

题目链接:uva 11806 - Cheerleaders 题目大意:在一个m行n列的矩阵网里放k个石子,问有多少种画法?每个格子最多放一个石子,所有石子必须用完,并且在第一行.最后一行.第一列和最后一列都得有石子. 解题思路:容斥原理,我们可以先求说在m?n的矩阵上放k个石子的种数C(nmk),减掉四条边界不放的情况就是答案了.所以枚举16种状态,用二进制数表示说四条边中那些边是不放石子的. 代码 #include <cstdio> #include <cstring> cons

UVA 10806 Cheerleaders

Cheerleaders Description C Cheerleaders In most professional sporting events, cheerleaders play a major role in entertaining the spectators. Their roles are substantial during breaks and prior to start of play. The world cup soccer is no exception. U

UVA 11806 - Cheerleaders(数论+容斥原理)

题目链接:11806 - Cheerleaders 题意:在一个棋盘上,要求四周的四行必须有旗子,问有几种摆法. 思路:直接算很容易乱掉,利用容斥原理,可知AUBUCUD = |A| + |B| + |C| + |D| - |AB| - |BC| - |AC| - |AD| - |BD| - |CD| + |ABC| + |ABD| + |ACD| + |BCD| - |ABCD| 由此利用位运算去计算即可 代码: #include <stdio.h> #include <string.

Cheerleaders UVA - 11806 计数问题

In most professional sporting events, cheerleaders play a major role in entertaining the spectators. Their roles are substantial during breaks and prior to start of play. The world cup soccer is no exception. Usually the cheerleaders form a group and