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 ≤ 20 and 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
2 2 2 1 2 3 2
Sample Output
Case 1: 0 Case 2: 2

k个石子,m*n的方格中让你在第一列、最后一列、第一行、最后一行都放置至少一个石子,求方案数;

思路: 容斥+组合数

通过第一行、最后一行、第一列、最后一列都没有的方案数求得

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
#define mod 1000007
const int MAXN = 505; // 组合上限
ll c[MAXN][MAXN]; // 组合数 void GetGroup()
{
c[0][0] = c[1][0] = c[1][1] = 1;
for (int i = 2; i < MAXN; i++)
{
c[i][0] = 1;
for (int j=1; j<=i; ++j)
c[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod; // 求模,防止结果过大
}
return ;
} int main()
{
int n,m,t,cas=0,k;
GetGroup();
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&m,&n,&k);
ll ans=0;
for(int i=0;i<16;i++)
{
int cnt=0,l=n,r=m;
if(i&1)
{
cnt++;
l--;
}
if(i&2)
{
cnt++;
r--;
}
if(i&4)
{
cnt++;
l--;
}
if(i&8)
{
cnt++;
r--;
}
if(cnt&1)
{
ans=(ans-c[l*r][k]+mod)%mod;
}
else
ans=(ans+c[l*r][k])%mod;
}
printf("Case %d: %lld\n",++cas,ans); }
return 0;
}

  

uva_11806_Cheerleaders的更多相关文章

随机推荐

  1. visual studio code断点调试react

    在项目配置文件   .vscode\launch.json 中添加:   "sourceMaps": true,   "skipFiles": [   &quo ...

  2. Anaconda 执行命令报ssl错误

  3. 颜色矩原理及Python实现

    原理 颜色矩(color moments)是由Stricker 和Orengo所提出的一种非常简单而有效的颜色特征.这种方法的数学基础在于图像中任何的颜色分布均可以用它的矩来表示.此外,由于颜色分布信 ...

  4. spring----面试题

    1.什么是Spring beans? Spring beans 是那些形成Spring应用的主干的java对象.它们被Spring IOC容器初始化,装配,和管理.这些beans通过容器中配置的元数据 ...

  5. html select 操作备份

    select动态添加option问题 JS操作:(未验证) 代码 var selid = document.getElementById("sltid"); for(var i=0 ...

  6. 【NLP_Stanford课堂】语言模型4

    平滑方法: 1. Add-1 smoothing 2. Add-k smoothing 设m=1/V,则有 从而每一项可以跟词汇表的大小相关 3. Unigram prior smoothing 将上 ...

  7. python IO 文件读写

    IO 由于CPU和内存的速度远远高于外设的速度,所以,在IO编程中,就存在速度严重不匹配的问题. 如要把100M的数据写入磁盘,CPU输出100M的数据只需要0.01秒,可是磁盘要接收这100M数据可 ...

  8. windows生成硬链接

    因工作电脑需要同时使用pl/sql和toad工具需要同时配置32位和64位oracle client如此增加了维护tnsnames.ora的复杂程度使用windows硬链接可以减少工作量,每次只修改源 ...

  9. July 08th 2017 Week 27th Saturday

    You are never wrong to do the right thing. 坚持做对的事情,永远都不会错. I think the translation may be not precis ...

  10. ZT北大青鸟营业额超20亿到不值一提 衰落的背后

    北大青鸟营业额超20亿到不值一提 衰落的背后 2013-10-18 08:18 王根旺  我要评论 (0) “北大青鸟是个悲剧!”说到曾经的IT培训业巨头,黑马导师.珍品网创始人曹允东惋惜道.在学大创 ...