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的更多相关文章
随机推荐
- 05_dubbo_aop
[对这行代码进行源码分析] ExtensionLoader<Protocol> loader = ExtensionLoader.getExtensionLoader(Protocol.c ...
- 初学js的穷举思想
初学者,最关机键的,就是掌握for的穷举思想. 穷举:穷尽.完全.全部. 具体方法: 外层:用for循环一一列举所有可能性 内层:用if语句进行判断,如果满足条件就输出,不满足的跳出进行下次循环. & ...
- 浮动属性(float)
(1.浮动是一种脱离标准文档流的形式. 作用:浮动就是用来制作多个盒子并排显示,也能设置宽高,负责网页排版 1 float:left; 左浮动 2 float:right; 右浮动 3 float: ...
- win10 x64 python3.6 pycharm 安装statsmodels
在pycharm下,安装statsmodels,会出现需要vc++14.0的错误提示. 这时可以到网站 https://www.lfd.uci.edu/~gohlke/pythonlibs/#word ...
- C#启动服务
启动服务的方法有很多种,简单的cmd下dos命名,手动启动,还有C#代码启动. 我们要实现的功能: 判断是否安装 是否启动 启动服务 关闭服务 我封装了有关服务的代码,如下: using System ...
- javascript 同源策略及web安全
同源策略为什么而生? JS可以读取/修改网页的值. 一个浏览器中,打开一个银行网站和一个恶意网站,如果恶意网站能够对银行网站进行修改,那么就会很危险. 你打开了恶意网站和另一个网站,如果没有同源限制, ...
- 【Leetcode】【Medium】Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- Idea中Git的使用和两种类型的冲突解决
一.Git冲突解决 在idea开发工具中使用Git时,主要用到的快捷按钮如下五个: 这五个按钮的使用说明及在idea中如何配置和使用git可参考https://github.com/DayThin ...
- Hbase集群部署及shell操作
本文详述了Hbase集群的部署. 集群部署 1.将安装包上传到集群并解压 scp hbase-0.99.2-bin.tar.gz mini1:/root/apps/ tar -zxvf hbase-0 ...
- 记一次挖掘115网盘反射型xss,08xss的储存型xss
记一次对115分站简单绕过过滤继续实现xss,08xss平台也中枪!! 115反射型xss url:http://115.qiye.115.com/disk/?ac=select_public_fil ...