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

《训练指南》p.108

#include <cstdio>

#include <cstring>

#include <cstdlib>



using namespace std;



const int MOD = 1000007;



const int MAXN = 500;



int C[MAXN][MAXN];



void init()

{

    memset( C, 0, sizeof(C) );

    C[0][0] = 1;

    for ( int i = 0; 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;

    }

    return;

}



int main()

{

    init();

    int T, cas = 0;

    scanf( "%d", &T );

    while ( T-- )

    {

        int M, N, K;

        int ans = 0;

        scanf( "%d%d%d", &M, &N, &K );

        for ( int S = 0; S < ( 1 << 4 ); ++S )

        {

            int cnt = 0;

            int r = M, c = N;

            if ( S & 1 ) --r, ++cnt;

            if ( S & 2 ) --r, ++cnt;

            if ( S & 4 ) --c, ++cnt;

            if ( S & 8 ) --c, ++cnt;

            if ( cnt & 1 ) ans = ( ans + MOD - C[r*c][K] )%MOD;

            else ans = ( ans + C[r*c][K] )%MOD;

        }

        printf( "Case %d: %d\n", ++cas, ans );

    }

    return 0;

}

 

你可能感兴趣的:(uva)