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. .NET开源工作流RoadFlow-流程运行-工作委托

    如果某一个人某一段时间不在单位,则可以将自己的工作委托给他人代为处理. 在 流程处理-->工作委托 中可以管理自己的委托,管理员也可以在 流程管理-->工作委托 中管理所有人的委托: 委托 ...

  2. WPF中使用定时器 DispatcherTimer 做TCP连接中的心跳 HeartBeat

    开发过程中经常遇到定时触发的需求,如:TCP/IP连接中,使用心跳包保持连接或检测连接是否已经中断. WPF中有多种定时器: 1.using System.Windows.Threading; 代码如 ...

  3. 项目经验:GIS<MapWinGIS>建模第四天

    实现了查询,与定位功能

  4. Python爬虫教程-21-xpath 简介

    本篇简单介绍 xpath 在python爬虫方面的使用,想要具体学习 xpath 可以到 w3school 查看 xpath 文档 xpath文档:http://www.w3school.com.cn ...

  5. 【Python】安装配置Anaconda

    优点:解决Python 库依赖问题 清华安装镜像 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

  6. Java基础之this关键字的作用

    this关键字主要存在三种应用 1.this调用本类中的属性,也就是说调用类中的成员变量: 2.this调用本类中的其他方法: 3.this调用本类中的其他构造方法,调用时要放在构造方法的首行,否则会 ...

  7. 基于以太坊的Token开发步骤

    Token开发步骤 一.准备工具1.安装以太坊brew tap ethereum/ethereumbrew install ethereum2.node:brew install nodejs3.安装 ...

  8. python爬虫系列:(一)、安装scrapy

    1.安装python 下载好安装包,一路next安装即可 2.把python和pip加入环境变量. 我的电脑----->右键“属性”------>“高级系统设置”------->“环 ...

  9. SQL Server ->> 与SQL Server服务配置相关的DMV

    1) sys.dm_server_services这个DMV可以告诉我们与当前版本的SQL Server相关的服务的启动状态和最后一次启动的时间,诸如这样的信息. SELECT * FROM sys. ...

  10. MySQL创建用户的三种方法

    前言:MySQL创建用户的方法分成三种:INSERT USER表的方法.CREATE USER的方法.GRANT的方法. 一.账号名称的构成方式 账号的组成方式:用户名+主机(所以可以出现重复的用户名 ...