###### UVA 11806 Cheerleaders

Question:
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
2
2 2 1
2 3 2
Sample Output
Case 1: 0
Case 2: 2

(http://acm.hust.edu.cn/vjudge/contest/121560#problem/C)

#include <iostream>
#include <cstdio>
using namespace std;
const int MOD=1000007;
typedef long long LL;
LL f[405][405];
int main()
{
for(int i=0;i<=400;i++)
{
f[i][i]=f[i][0]=1;
for(int j=1;j<i;j++)
f[i][j]=(f[i-1][j-1]+f[i-1][j])%MOD;  //打表，打印杨辉三角
}
int T,n,m,k;
scanf("%d",&T);
for(int i=1;i<=T;i++)
{
scanf("%d%d%d",&n,&m,&k);
LL way=0;
for(int j=0;j<=15;j++)
{
int t=0,l=n,c=m ;
if(j&1)      //充分利用位运算求p(a)+p(b)+p(c)......-p(abcd)
{t++;l--;}
if(j&2)
{t++;c--;}
if(j&4)
{t++;l--;}
if(j&8)
{t++;c--;}
if(t%2==0)  //原本偶数应该被减，但现在是总数减去，所以偶数被加，奇数被减
way=(way+f[c*l][k])%MOD;
else way=(way+MOD-f[c*l][k])%MOD; //减法求MOD
}
printf("Case %d: %lld\n",i,way);
}
return 0;
}

#### E Cheerleaders （UVA 11806）

2016-04-02 17:15:38

#### uva 11806 - Cheerleaders(容斥原理)

2014-05-14 12:36:04

#### UVAoj 11806 - Cheerleaders

2015-08-25 21:19:01

#### UVa 11806 Cheerleaders 【容斥】【入门】

2017-07-29 11:47:18

#### UVA 11806 - Cheerleaders

2013-10-28 14:05:21

#### uva 11806 Cheerleaders

2014-08-04 14:31:17

#### UVA - 11806 —— Cheerleaders

2016-05-18 21:35:50

#### UVA - 11806 Cheerleaders

2014-11-12 22:29:18

#### uva 11806 Cheerleaders【容斥原理】

2015-04-22 07:32:09

#### UVA 11806 Cheerleaders（容斥原理）

2017-05-18 15:43:21