Cheerleaders UVA - 11806

 题目大意是:

在一个m行n列的矩形网格中放置k个相同的石子,问有多少种方法?每个格子最多放一个石子,所有石子都要用完,并且第一行、最后一行、第一列、最后一列都要有石子。

 容斥原理。如果只是n * m放石子,那么最后的结果,就是C(n*m,k).我们设A为第一行不放石头的总数,B为最后一行不放石子的总数,C为第一列不放石子的总数,D为最后一列不放石子的总数.则问题转化为在全集S中,求不在A,B,C,D部分的解.则答案为S - | A | - | B |- | C | - | D | + | A ^ B|......用一个二进制枚举状态,统计就可以了。

// Asimple
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define INF 0x3f3f3f3f
#define mod 1000007
#define debug(a) cout<<#a<<" = "<<a<<endl
#define test() cout<<"============"<<endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 500+5;
ll n, m, T, len, cnt, num, ans, Max, k;
ll a[maxn][maxn];void input(){
    memset(a, 0, sizeof(a));
    a[0][0] = 1;
    for(int i=0; i<maxn; i++) {
        a[i][0] = a[i][i] = 1;
        for(int j=1; j<=i; j++) {
            a[i][j] = (a[i-1][j] + a[i-1][j-1])%mod;
        }
    }
    
    int cas = 1;
    cin >> T;
    while( T-- ) {
        cin >> n >> m >> k;
        ans = 0;
        for(int s=0; s<16; s++) {
            cnt = 0;
            int r = n, c = m;
            if( s&1 ) { cnt++; r--; }
            if( s&2 ) { cnt++; r--; }
            if( s&4 ) { cnt++; c--; }
            if( s&8 ) { cnt++; c--; }
            if( cnt&1 ) ans = ( ans+mod - a[r*c][k])%mod;
            else ans = ( ans + a[r*c][k])%mod;
        }
        cout << "Case " << cas ++ << ": "; 
        cout << ans << endl;
    }
}

int main() {
    input();
    return 0;
} 

 

转载于:https://www.cnblogs.com/Asimple/p/7412588.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值