链接
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2906
题解
容斥裸题
Cknm−2Ck(n−1)m−2Ckn(m−1)+4Ck(n−1)(m−1)+Ck(n−2)m+Ckn(m−2)−Ck(n−2)(m−2)
C
n
m
k
−
2
C
(
n
−
1
)
m
k
−
2
C
n
(
m
−
1
)
k
+
4
C
(
n
−
1
)
(
m
−
1
)
k
+
C
(
n
−
2
)
m
k
+
C
n
(
m
−
2
)
k
−
C
(
n
−
2
)
(
m
−
2
)
k
代码
//容斥
#include <bits/stdc++.h>
#define mod 1000007ll
#define maxn 410
using namespace std;
int C[maxn][maxn];
void preprocess()
{
int i, j;
for(i=0;i<maxn;i++)C[i][0]=1;
for(i=1;i<maxn;i++)for(j=1;j<=i;j++)C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
}
int main()
{
int i, m, n, T, kase=0, ans, k;
preprocess();
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
if(k<2 or k>n*m)ans=0;
else ans=
C[n*m][k]
-2*C[(n-1)*m][k]-2*C[n*(m-1)][k]
+4*C[(n-1)*(m-1)][k]+C[(n-2)*m][k]+C[n*(m-2)][k]
-2*C[(n-1)*(m-2)][k]-2*C[(n-2)*(m-1)][k]
+C[(n-2)*(m-2)][k];
printf("Case %d: %d\n",++kase,((ans%mod)+mod)%mod);
}
return 0;
}