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 eld. 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 rst 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 rst 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
 
简单的计数问题;
题目所说:第一行,最后一行,第一列,最后一列都得有石子;
设集合A:不在第一行,
集合B:不在最后一行;
集合C:不在第一列;
集合D:不在最后一列;
总集合为S的话,那么我们要求的就是在S中而且不在集合ABCD中的个数;
那我们用二进制来表示,总的数量为2^4=16种情况;
容斥一下就Ok了;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 2000005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e6 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int c[503][503];
int n, m, k;
void init() {
c[0][0] = 1;
for (int i = 0; i <= 503; 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 main() {
// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T; cin >> T;
init(); int tot = 0;
while (T--) {
tot++;
cin >> n >> m >> k;
cout << "Case " << tot << ": ";
int sum = 0;
for (int i = 0; i < 16; i++) {
int bk = 0;
int r = n, C = m;
if (i & 1) { bk++; r--; }
if (i & 2) { bk++; r--; }
if (i & 4) { bk++; C--; }
if (i & 8) { bk++; C--; }
if (bk % 2) {
sum = (sum + mod - c[C*r][k]) % mod;
}
else sum = (sum + c[C*r][k]) % mod;
}
cout << sum << endl;
}
return 0;
}

Cheerleaders UVA - 11806 计数问题的更多相关文章

  1. Cheerleaders UVA - 11806

    题目大意是: 在一个m行n列的矩形网格中放置k个相同的石子,问有多少种方法?每个格子最多放一个石子,所有石子都要用完,并且第一行.最后一行.第一列.最后一列都要有石子. 容斥原理.如果只是n * m放 ...

  2. Cheerleaders UVA - 11806(容斥+二进制技巧)

    #include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...

  3. uva 11806 Cheerleaders

    // uva 11806 Cheerleaders // // 题目大意: // // 给你n * m的矩形格子,要求放k个相同的石子,使得矩形的第一行 // 第一列,最后一行,最后一列都必须有石子. ...

  4. UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)

    UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举) 题意分析 给出n*m的矩形格子,给出k个点,每个格子里面可以放一个点.现在要求格子的最外围一圈的每行每列,至少要放一个 ...

  5. UVA 11806 Cheerleaders dp+容斥

    In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...

  6. UVa 11806 Cheerleaders (容斥原理+二进制表示状态)

    In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...

  7. uva 11806 Cheerleaders (容斥)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. UVA 11806 Cheerleaders (组合+容斥原理)

    自己写的代码: #include <iostream> #include <stdio.h> #include <string.h> /* 题意:相当于在一个m*n ...

  9. UVA 11806 Cheerleaders (容斥原理)

    题意 一个n*m的区域内,放k个啦啦队员,第一行,最后一行,第一列,最后一列一定要放,一共有多少种方法. 思路 设A1表示第一行放,A2表示最后一行放,A3表示第一列放,A4表示最后一列放,则要求|A ...

随机推荐

  1. SonarQube在CentOS上的安装

    1 简介 SonarQube 是一个用于代码质量管理的开放平台.通过插件机制,Sonar 可以集成不同的测试工具,代码分析工具,以及持续集成工具.与持续集成工具(例如 Hudson/Jenkins 等 ...

  2. xml和configparser模块

    一.xml模块 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单, 但至今很多传统公司如金融行业的很多系统的接口还主要是xml. xml的格式如下,就是通过 ...

  3. 用rand5()生成rand(n)

    问题:有函数rand5(),它能够等概率生成[0,5)之间的整数.由rand5()构造rand(n)使其能够等概率生成[0,n)之间的整数. 思路1:有rand5()先生成等概率生成0和1的rand0 ...

  4. [luogu3391] 【模板】文艺平衡树(fhq-treap反转区间)

    解题关键:无旋treap模板. #include<iostream> #include<cstdio> #include<cstring> #include< ...

  5. Memcached 原理

    memcached  是以一个守护进程的方式运行于一个服务器和多个服务器之间的,等待接受客户端的连接操作,客户端可以有各种语言编写.(例如PHP). php 在客户端与服务器建立连接以后,接下来的事情 ...

  6. Java 基于quartz实现定时 之二(XML方式配置)

    <!-- 在spring核心配置文件中进行如下配置 --> <!-- Spring基于quartz定时任务 --> <bean id="triggerByBea ...

  7. Python3 使用requests库读取本地保存的cookie文件实现免登录访问

    1.  读取selenium模块保存的本地cookie文件来访问知乎 读取http://www.cnblogs.com/strivepy/p/9233389.html保存的本地cookie来访问知乎的 ...

  8. Tarjan算法求出强连通分量(包含若干个节点)

    [功能] Tarjan算法的用途之一是,求一个有向图G=(V,E)里极大强连通分量.强连通分量是指有向图G里顶点间能互相到达的子图.而如果一个强连通分量已经没有被其它强通分量完全包含的话,那么这个强连 ...

  9. css总结14:CSS 分页实例

    1 作用:如果你的网站有很多个页面,你就需要使用分页来为每个页面做导航. 例1 :以下实例演示了如何使用 HTML 和 CSS 来创建分页: 正常样式 <!DOCTYPE html>< ...

  10. css总结4:input 去掉外边框,placeholder的字体颜色、字号

    1 input 标签去除外边框: 在进行webAPP开发时,input外边框非常影响美观,去除外边框方法如下: <input style="border: 0px;outline:no ...