UVa 11806 - Cheerleaders (组合计数+容斥原理)

《训练指南》p.108

#include <cstdio>
#include <cstring>
#include <cstdlib> using namespace std; const int MOD = ; const int MAXN = ; int C[MAXN][MAXN]; void init()
{
memset( C, , sizeof(C) );
C[][] = ;
for ( int i = ; i < MAXN; ++i )
{
C[i][] = C[i][i] = ;
for ( int j = ; j < i; ++j )
C[i][j] = ( C[i-][j] + C[i-][j-] ) % MOD;
}
return;
} int main()
{
init();
int T, cas = ;
scanf( "%d", &T );
while ( T-- )
{
int M, N, K;
int ans = ;
scanf( "%d%d%d", &M, &N, &K );
for ( int S = ; S < ( << ); ++S )
{
int cnt = ;
int r = M, c = N;
if ( S & ) --r, ++cnt;
if ( S & ) --r, ++cnt;
if ( S & ) --c, ++cnt;
if ( S & ) --c, ++cnt;
if ( cnt & ) ans = ( ans + MOD - C[r*c][K] )%MOD;
else ans = ( ans + C[r*c][K] )%MOD;
}
printf( "Case %d: %d\n", ++cas, ans );
}
return ;
}
上一篇:【递推】【组合数】【容斥原理】UVA - 11806 - Cheerleaders


下一篇:UVA 11806 Cheerleaders (容斥原理