UVA - 11806 - Cheerleaders (递推)
来源:互联网 发布:龙岗双龙淘宝培训 编辑:程序博客网 时间:2024/06/15 21:07
UVA - 11806
Submit 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. Kdenotes 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
Source
Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Counting :: Examples
Root :: Prominent Problemsetters :: Shamim Hafiz
AC代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MOD = 1000007;const int MAXK = 500;int C[MAXK+10][MAXK+10];int main(){memset(C, 0, sizeof(C));C[0][0] = 1;for(int i=0; i <= MAXK; i++){C[i][0] = C[i][i] = 1;for(int j=1; j<i; j++)C[i][j] = (C[i-1][j]+ C[i-1][j-1]) % MOD;}int T;scanf("%d", &T);for(int cas = 1; cas <= T; cas++){int n, m, k, sum = 0;scanf("%d %d %d", &n, &m, &k);for(int s = 0; s < 16; s++){int b = 0, r = n, c = m;if(s & 1) { r--; b++; }if(s & 2) { r--; b++; }if(s & 4) { c--; b++; }if(s & 8) { c--; b++; }if(b & 1) sum = (sum + MOD - C[r*c][k] ) % MOD;else sum = (sum + C[r*c][k]) % MOD;}printf("Case %d: %d\n", cas, sum);}return 0;}
- UVA - 11806 - Cheerleaders (递推)
- E Cheerleaders (UVA 11806)
- 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
- UVA - 11806 Cheerleaders
- uva 11806 Cheerleaders
- UVA - 11806 Cheerleaders
- UVA 11806 Cheerleaders
- UVa 11806 Cheerleaders
- UVA 11806 Cheerleaders
- 【瞎搞】ZOJ 3045 Random or Shuffle
- kill,nohup
- 寒冰王座
- iOS App启动页面
- Cocos2d-X 3.4版-技能冷却按钮《赵云要格斗》
- UVA - 11806 - Cheerleaders (递推)
- Azure+PHP 网站如何设置伪静态
- HTML5 vs.原生,世界究竟是谁的?
- ios中NSDate dateWithTimeIntervalSinceNow:方法的限制
- Android 操作系统的内存回收机制
- Qt5官方demo解析集34——Concentric Circles Example
- 软键盘弹出问题
- hibernate 延迟加载
- 最近做Qt的一个界面需要按钮在没悬浮时背景是透明