uva_11806_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 ≤ 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的更多相关文章
随机推荐
- FCKeditor文本编辑器的使用方法
FCKeditor是一个功能强大支持所见即所得功能的文本编辑器,可以为用户提供微软office软件一样的在线文档编辑服务. 它不需要安装任何形式的客户端,兼容绝大多数主流浏览器,支持ASP.Net.A ...
- RocketMQ读书笔记4——NameServer(MQ的协调者)
[NameServer简述] 对于一个消息队列集群来说,系统由很多机器组成,每个机器的角色.IP地址都不相同,而且这些信息是变动的(如在某些情况下,会有新的Producer或Consumer加入). ...
- ArcGIS for JavaScript 关于路径开发的一些记录(三)
最近被一个bug困扰了两天~ 我新发布了一个NAserver(路径分析服务),但是放在之前的代码里面发现不能生成路径.经过我的调试发现并没有代码并没有报错,并且能够返回所生成路径的Graphic la ...
- C# Winform窗体和控件自适应大小
1.在项目中创建类AutoSizeForm AutoSizeForm.cs文件代码: using System; using System.Collections.Generic; using Sys ...
- SpringBoot2.0+Mybatis+PageHelper+Redis实现缓存
1.在maven引入相关的依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactI ...
- margin的auto的理解 top,left[,bottom,right] position
auto auto 总是试图充满父元素 margin有四个值: All the margin properties can have the following values: auto - the ...
- 动态注册broadcast的安全考虑
一.android service通知activity更新方式有1. service 通过广播的形式发送broadcast,向这个activity的内部类发广播的消息来更新界面2. service直接 ...
- mac和windows自动清理内存工具
因为我比较懒,所以需要一款能自动清理电脑内存的工具,目的是设置内存最小值,然后自动清理. mac: drcleaner windows: MaxMem win10设置开机启动地址:C:\Program ...
- SQL Server ->> SQL Server 2016功能改进之 -- Update Statistics
1) 以前SQL Server更新一张表/索引的间隔是固定的,创建时更新一次,到了500行时更新第二次,接下来就是呈百分比式的间隔去更新,距离数据修改量达到表的行数量的的20%再次触发更新.但是这样的 ...
- .Net ->> iTextSharp工具读取PDF文本内容
分享一个开源的C#DLL,可以读取PDF文本内容. 地址:http://sourceforge.net/projects/itextsharp/ 这里还有相关的链接:http://www.codepr ...