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
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define read(x,y) scanf("%d%d",&x,&y)
#define root l,r,rt
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ll long long
const int maxn =505;
const int mod=1e6+7;
/*
题目意思:就是一个矩形方块,
然后要求放k个石子,第一行和第一列,
最后一行和最后一列,都要放有石子,
求方案数。
容斥定理水题,
求组合数因为数据量太小,可以直接递推求得。
然后就是惯用的枚举子集,增减状态方案数。
最后注意取的模是10^6+7不是九次方
*/
///容斥定理枚举子集
int n,m,k;
int C[maxn][maxn];
int main()
{
memset(C,0,sizeof(C)); C[0][0]=1;
for(int i=1;i<maxn;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 ca=1;ca<=t;ca++)
{
scanf("%d%d%d",&n,&m,&k);
int ans=0;
for(int s=0;s<16;s++)
{
int r=n,c=m,b=0;
if(s&1) r--,b++;
if(s&2) r--,b++;
if(s&4) c--,b++;
if(s&8) c--,b++;
if(b&1) ans=((ans-C[r*c][k])%mod+mod)%mod;
else ans=(ans+C[r*c][k])%mod;
}
printf("Case %d: %d\n",ca,ans);
}
return 0;
}