传送门 \looparrowright

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 center 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×nm\times 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 T50T ≤ 50, which denotes the number of test cases.
TT lines then follow each describing one test case. Each case consists of three nonnegative integers, 2m,n202 ≤ m,n ≤ 20 and k500k ≤ 500. Here mm is the number of rows and nn 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 10000071000007.

Sample Input

2
2 2 1
2 3 2

Sample Output

Case 1: 0
Case 2: 2

Idea

直接考虑四个边界的放置情况较难,采用正难则反的策略。考虑第一行不放棋子,最后一行不放棋子,第一列不放棋子,最后一列不放棋子的情况。
AA 为第一行不妨棋子的方案集合,BB 为最后一行不放棋子的方案集合,CC 为第一列不放棋子的方案集合,DD 为最后一列不放棋子的方案集合。在 m×nm\times n 棋盘中放置 kk 个棋子的总方案数为 $\begin{pmatrix}mn\\k\end{pmatrix}$,则满足题目要求的方案数为 $\begin{pmatrix}mn\\k\end{pmatrix}-|A\cup B\cup C\cup D|$。
根据容斥原理,ABCD|A\cup B\cup C\cup D|==A|A|++B|B|++C|C|++D|D|-AB|A\cap B|-AC|A\cap C|-AD|A\cap D|-BC|B\cap C|-BD|B\cap D|-CD|C\cap D|++ABC|A\cap B\cap C|++ABD|A\cap B\cap D|++ACD|A\cap C\cap D|++BCD|B\cap C\cap D|-ABCD|A\cap B\cap C\cap D|
AA:第一行不放棋子,$|A|=\begin{pmatrix}(m-1)n\\k\end{pmatrix}$。
BB:最后一行不放棋子,$|B|=\begin{pmatrix}(m-1)n\\k\end{pmatrix}$。
CC:第一列不放棋子,$|C|=\begin{pmatrix}m(n-1)\\k\end{pmatrix}$。
DD:最后一列不放棋子,$|D|=\begin{pmatrix}m(n-1)\\k\end{pmatrix}$。
ABA\cap B:第一行和最后一行都不放棋子,$|A\cap B|=\begin{pmatrix}(m-2)n\\k\end{pmatrix}$。
ACA\cap C:第一行和第一列都不放棋子,$|A\cap C|=\begin{pmatrix}(m-1)(n-1)\\k\end{pmatrix}$。
ADA\cap D:第一行和最后一列都不放棋子,$|A\cap D|=\begin{pmatrix}(m-1)(n-1)\\k\end{pmatrix}$。
BCB\cap C:最后一行和第一列都不放棋子,$|B\cap C|=\begin{pmatrix}(m-1)(n-1)\\k\end{pmatrix}$。
BDB\cap D:最后一行和最后一列都不放棋子,$|B\cap D|=\begin{pmatrix}(m-1)(n-1)\\k\end{pmatrix}$。
CDC\cap D,第一列和最后一列都不放棋子,$|C\cap D|=\begin{pmatrix}m(n-2)\\k\end{pmatrix}$。
ABCA\cap B\cap C,第一行、最后一行、第一列都不放棋子,$|A\cap B\cap C|=\begin{pmatrix}(m-2)(n-1)\\k\end{pmatrix}$。
ABDA\cap B\cap D,第一行、最后一行、最后一列都不放棋子,$|A\cap B\cap D|=\begin{pmatrix}(m-2)(n-1)\\k\end{pmatrix}$。
ACDA\cap C\cap D,第一行、第一列、最后一列都不放棋子,$|A\cap C\cap D|=\begin{pmatrix}(m-1)(n-2)\\k\end{pmatrix}$。
BCDB\cap C\cap D,最后一行、第一列、最后一列都不放棋子,$|B\cap C\cap D|=\begin{pmatrix}(m-1)(n-2)\\k\end{pmatrix}$。
ABCDA\cap B\cap C\cap D:第一行、最后一行、第一列、最后一列都不放棋子,$|A\cap B\cap C\cap D|=\begin{pmatrix}(m-2)(n-2)\\k\end{pmatrix}$。
综上所述,答案为 $\begin{pmatrix}mn\\k\end{pmatrix}$$-$$2\times \begin{pmatrix}(m-1)n\\k\end{pmatrix}$$-$$2\times \begin{pmatrix}m(n-1)\\k\end{pmatrix}$$+$$\begin{pmatrix}(m-2)n\\k\end{pmatrix}+\begin{pmatrix}m(n-2)\\k\end{pmatrix}$$+$$4\times \begin{pmatrix}(m-1)(n-1)\\k\end{pmatrix}$$-$$2\times \begin{pmatrix}(m-2)(n-1)\\k\end{pmatrix}$$-$$2\times \begin{pmatrix}(m-1)(n-2)\\k\end{pmatrix}$$+$$\begin{pmatrix}(m-2)(n-2)\\k\end{pmatrix}$。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;
const int mod=1000007;
const int N=502;
int C[N][N];
int m,n,k;
void init()
{
int i,j;
for(i=0;i<N;i++)
{
C[i][0]=C[i][i]=1;
for(j=0;j<i;j++)
{
C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
}
}
}
int main()
{
init();
int _,CASE=0;
for(cin>>_;_;_--)
{
scanf("%d%d%d",&m,&n,&k);
printf("Case %d: %lld\n",++CASE,
((C[m*n][k]
-2*C[(m-1)*n][k]-2*C[m*(n-1)][k]
+C[(m-2)*n][k]+C[m*(n-2)][k]+4*C[(m-1)*(n-1)][k]
-2*C[(m-2)*(n-1)][k]-2*C[(m-1)*(n-2)][k]
+C[(m-2)*(n-2)][k])%mod+mod)%mod);
}
return 0;
}

PostScript

注意!1000007=29×344831000007=29\times 3448310000071000007 不是质数。求 xx 的逆元时,万万不可直接利用 inv(x)xp2(modp)\mathrm{inv}(x)\equiv x^{p-2}\pmod p。这题数据范围不大,老老实实打表吧。