【UVA11806 Cheerleaders】 题解

时间:2022-01-01 03:01:23

题目链接:https://www.luogu.org/problemnew/show/UVA11806

容斥原理+组合数

正着找合♂fa的不好找,那就用总方案数-不合♂fa的

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1000;
const int mod = 1e6 + 7;
int T, k, m, n, ans, C[maxn][maxn];
void init()
{
C[0][0] = 1; C[1][0] = 1; C[1][1] = 1;
for(int i = 2; i <= 500; i++)
{
C[i][0] = 1;
for(int j = 1; j <= i; j++)
C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
}
}
int main()
{
init();
cin>>T;
for(int a = 1; a <= T; a++)
{
ans = 0;
cin>>n>>m>>k;
for(int i = 0; i < (1 << 4); i++)
{
int now_n = n, now_m = m, flag = 0;
if(i & (1 << 0)) now_n--, flag++;
if(i & (1 << 1)) now_n--, flag++;
if(i & (1 << 2)) now_m--, flag++;
if(i & (1 << 3)) now_m--, flag++;
if(flag % 2 == 1) ans = (ans - C[now_n*now_m][k] + mod)%mod;
else ans = (ans + C[now_n*now_m][k])%mod;
}
cout<<"Case "<<a<<": "<<ans%mod<<"\n";
}
}