UVA - 11806 组合计数+容斥

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2906
题目大意:
在这里插入图片描述

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int mod=1000007;

LL c[505][505];
void get_c(){
    memset(c, 0, sizeof(c));
    c[0][0]=1;
    for(int i=0; i<505; 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;
        }
    }
}

int main()
{
    get_c();
    int t, T=1;
    scanf("%d", &t);
    while(t--){
        int n, m, k;
        scanf("%d%d%d",&n, &m, &k);
        LL sum=0;
        for(int s=0; s<(1<<4); s++){//16个搭配
            int b=0, x=n, y=m;      //b:集合个数 x:行 y:列
            if(s&1){
                x--, b++;
            }
            if(s&2){
                x--, b++;
            }
            if(s&4){
                y--, b++;
            }
            if(s&8){
                y--, b++;
            }
            sum=(sum+c[x*y][k]*(b%2?-1:1)+mod)%mod;//奇减偶加
        }
        printf("Case %d: %lld\n", T++, sum);
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值