UVa 11806 - Cheerleaders (组合数学 容斥原理)
来源:互联网 发布:淘宝宝贝标题违规规则 编辑:程序博客网 时间:2024/05/16 08:17
Cheerleaders
[Submit] [Go Back] [Status]
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. Usually the cheerleaders form a group and perform at the centre of the field. In addition to this group, some of them are placed outside the side line so they are closer to the spectators. The organizers would like to ensure that at least one cheerleader is located on each of the four sides. For this problem, we will model the playing ground as an M*N rectangular grid. The constraints for placing cheerleaders are described below:
§ There should be at least one cheerleader on each of the four sides. Note that, placing a cheerleader on a corner cell would cover two sides simultaneously.
§ There can be at most one cheerleader in a cell.
§ All the cheerleaders available must be assigned to a cell. That is, none of them can be left out.
The organizers would like to know, how many ways they can place the cheerleaders while maintaining the above constraints. Two placements are different, if there is at least one cell which contains a cheerleader in one of the placement but not in the other.
Input
The first line of input contains a positive integer T<=50, which denotes the number of test cases. T lines then follow each describing one test case. Each case consists of three nonnegative integers, 2<=M, N<=20 and K<=500. Here M is the number of rows and N is the number of columns in the grid. K denotes the number of cheerleaders that must be assigned to the cells in the grid.
Output
For each case of input, there will be one line of output. It will first contain the case number followed by the number of ways to place the cheerleaders as described earlier. Look at the sample output for exact formatting. Note that, the numbers can be arbitrarily large. Therefore you must output the answers modulo 1000007.
Sample Input
Sample Output
2
2 2 1
2 3 2
Case 1: 0
Case 2: 2
[Submit] [Go Back] [Status]
题意:
n行m列的矩形格子里面放k个石子,每个格子只能放一个,第一行 最后一行 第一列 最后一列 都必须有石子,问方案数有多少
正面不好求可以通过求反面来求
全集S=C(n*m, k)
A表示第一行不放的方案集合,B表示最后一行不放的方案集合,C表示第一列不放的方案集合,D表示最后一列不放的方案集合
那么答案就是 { S - { A U B U C U D } }
就是求 A∪B∪C∪D = |A|+|B|+|C|+|D| - |A∩B| - |B∩C| - |C∩A|- |A∩D| - |B∩D| - |C∩D|+|A∩B∩C|+|A∩B∩D| +|A∩C∩D| +|B∩C∩D| -|A∩B∩C∩D|
写出来就能明白大白上面的代码了 加减和奇偶有关
#include <cstdio>#include <iostream>#include <vector>#include <algorithm>#include <cstring>#include <string>#include <map>#include <cmath>#include <queue>#include <set>using namespace std;//#define WIN#ifdef WINtypedef __int64 LL;#define iform "%I64d"#define oform "%I64d\n"#define oform1 "%I64d"#elsetypedef long long LL;#define iform "%lld"#define oform "%lld\n"#define oform1 "%lld"#endif#define S64I(a) scanf(iform, &(a))#define P64I(a) printf(oform, (a))#define P64I1(a) printf(oform1, (a))#define REP(i, n) for(int (i)=0; (i)<n; (i)++)#define REP1(i, n) for(int (i)=1; (i)<=(n); (i)++)#define FOR(i, s, t) for(int (i)=(s); (i)<=(t); (i)++)const int INF = 0x3f3f3f3f;const double eps = 10e-9;const double PI = (4.0*atan(1.0));const int maxk = 500 + 20;const int MOD = 1000007;int C[maxk][maxk];void init() { memset(C, 0, sizeof(C)); C[0][0] = 1; for(int i=1; i<maxk; i++) { C[i][0] = C[i][i] = 1; for(int j=1; j<i; j++) { C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD; } }}int main() { int T; init(); scanf("%d", &T); for(int kase=1; kase<=T; kase++) { int n, m, k; scanf("%d%d%d", &n, &m, &k); int sum = 0; for(int i=1; i<16; i++) { int r = n, c = m, b = 0; if(i&1) { r--; b++; } if(i&2) { r--; b++; } if(i&4) { c--; b++; } if(i&8) { c--; b++; } if(b&1) sum = (sum + C[r*c][k]) % MOD; else sum = (sum - C[r*c][k] + MOD) % MOD; } int ans = (C[n*m][k] - sum + MOD) % MOD; printf("Case %d: %d\n", kase, ans); } return 0;}
- UVa 11806 - Cheerleaders (组合数学 容斥原理)
- UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)
- UVA 11806 Cheerleaders(容斥原理)(组合数)
- UVA 11806 Cheerleaders(容斥原理 + 组合数)
- UVA 11806 Cheerleaders(容斥原理)
- Cheerleaders +容斥原理+组合数+UVA
- UVA 11806-Cheerleaders-容斥原理+组合数打表
- uva 11806 Cheerleaders 容斥原理+组合数
- UVA 11806 - Cheerleaders (容斥原理)
- UVa 11806 Cheerleaders / 容斥原理
- uva 11806 - Cheerleaders(容斥原理)
- UVA 11806 Cheerleaders (容斥原理)
- uva 11806 Cheerleaders (容斥原理)
- uva 11806 Cheerleaders【容斥原理】
- uva 11806 - Cheerleaders(容斥原理+二进制)
- uva 11806 Cheerleaders 容斥原理
- CheerLeaders Uva 11806(容斥原理)
- UVa 11806 Cheerleaders 解题报告(容斥原理)
- ExportData4Mssql
- java队列和优先级队列
- winusb资料汇总
- HDU4939:Stupid Tower Defense(DP)
- servlet/filter/listener/interceptor区别与联系
- UVa 11806 - Cheerleaders (组合数学 容斥原理)
- Android修炼之道——Theme自定义ActionBar
- gsoap高性能服务器的开发
- Nginx进程模型
- 黑马程序员_面向对象2
- POJ 3294 后缀数组:求不小于k个字符串中的最长子串
- poj3974 Palindrome,回文串,Manacher
- Win7 IIS 另一个程序正在使用此文件,进程无法访问 解决办法
- Java反射机制