UVa11806 Cheerleaders

容斥问题

 

考虑上下左右四个边界只满足其中1/2/3/4个边界有人的情况,可以用组合数算。

总共只有16种情况。

可以用容斥原理求解。

 

 1 /*by SilverN*/
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 #include<vector>
 8 using namespace std;
 9 const int mod=1000007;
10 const int mxn=510;
11 int read(){
12     int x=0,f=1;char ch=getchar();
13     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
14     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
15     return x*f;
16 }
17 int n,m,k;
18 int c[mxn][mxn];
19 void init(){
20     for(int i=0;i<=500;i++){
21         c[i][0]=1;
22         for(int j=1;j<=i;j++)
23             c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
24     }
25     return;
26 }
27 int main(){
28     int i,j;
29     int T=read(),cas=0;
30     init();
31     while(T--){
32         n=read();m=read();k=read();
33         int ct,a,b;
34         int ans=0;
35         for(i=0;i<=15;i++){
36             ct=0;a=n;b=m;
37             if(i&1)a--,ct++;
38             if(i&2)b--,ct++;
39             if(i&4)a--,ct++;
40             if(i&8)b--,ct++;
41             if(ct&1) ans=((ans-c[a*b][k])%mod+mod)%mod;
42             else (ans+=c[a*b][k])%=mod;
43         }
44         printf("Case %d: %d\n",++cas,ans);
45     }
46     return 0;
47 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/6273900.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值