UVA - 11806 Cheerleaders

Time Limit: 2000MSMemory Limit: Unknown64bit IO Format: %lld & %llu

Submit Status

Description

Download as PDF

C

Cheerleaders

 

In most professional sporting events, cheerleaders play a major role in entertaining the spectators. Their roles are substantial during breaks and prior to start of play. The world cup soccer is no exception. Usually the cheerleaders form a group and perform at the centre of the field. In addition to this group, some of them are placed outside the side line so they are closer to the spectators. The organizers would like to ensure that at least one cheerleader is located on each of the four sides. For this problem, we will model the playing ground as an M*N rectangular grid. The constraints for placing cheerleaders are described below:

 

§  There should be at least one cheerleader on each of the four sides. Note that, placing a cheerleader on a corner cell would cover two sides simultaneously.

§  There can be at most one cheerleader in a cell.

§  All the cheerleaders available must be assigned to a cell. That is, none of them can be left out.

 

 

The organizers would like to know, how many ways they can place the cheerleaders while maintaining the above constraints. Two placements are different, if there is at least one cell which contains a cheerleader in one of the placement but not in the other. 

 

 

 

Input

 

The first line of input contains a positive integer T<=50, which denotes the number of test cases. T lines then follow each describing one test case. Each case consists of three nonnegative integers, 2<=M, N<=20and K<=500. Here M is the number of rows and N is the number of columns in the grid. K denotes the number of cheerleaders that must be assigned to the cells in the grid.

 

 

Output

 

For each case of input, there will be one line of output. It will first contain the case number followed by the number of ways to place the cheerleaders as described earlier. Look at the sample output for exact formatting. Note that, the numbers can be arbitrarily large. Therefore you must output the answers modulo 1000007.

 

Sample Input

Sample Output

2

2 2 1

2 3 2

Case 1: 0

Case 2: 2


Source


Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Counting ::  Examples
Root :: Prominent Problemsetters ::  Shamim Hafiz




分析:
刘汝佳大白书里的题,较水。
组合数学+容斥原理+按位运算。
ac代码:
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MOD=1000007;
const int maxk=500;
int C[maxk+2][maxk+2];//注意不要数组越界


int main()
{
   memset(C,0,sizeof(C));
   C[0][0]=1;
   for(int i=0;i<=maxk;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 t;
   scanf("%d",&t);
   for(int kase=1;kase<=t;kase++)
   {
       int n,m,k,sum=0;
       scanf("%d%d%d",&n,&m,&k);
       for(int s=0;s<16;s++)
       {
           int b=0,r=n,c=m;
           if(s&1)
           {
               r--;b++;
           }
           if(s&2)
           {
               r--;b++;
           }
           if(s&4)
           {
               c--;b++;
           }
           if(s&8)
           {
               c--;b++;
           }
           if(b&1) sum=(sum+MOD-C[r*c][k])%MOD;
           else sum=(sum+C[r*c][k])%MOD;
       }
       printf("Case %d: %d\n",kase,sum);
   }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值