uva 11806 Cheerleaders

我们直接求解不好处理,那么反向考虑,四个边至少有一条边没有解的情况

ac代码:

#include <cstdio>
#include <cstring>

const int N = 500;
const int MOD = 1000007;

int n, m, k, C[N+10][N+10];

void init () {

    for (int i = 0; i < N; i++) {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < i; j++)
            C[i][j] = (C[i-1][j-1] + C[i-1][j])%MOD;
    }
}

int main () {
    init ();

    int cas;
    scanf("%d", &cas);
    for (int i = 1; i <= cas; i++) {
        scanf("%d%d%d", &n, &m, &k);
        int ans = 0;

        for (int s = 0; s < 16; s++) {
            int cnt = 0, r = n, c = m;

            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", i, ans);
    }

    return 0;
}

 

posted @ 2017-08-05 11:11  猪突猛进!!!  阅读(116)  评论(0编辑  收藏  举报