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

给你一个n*m大的操场,上面站上k个啦啦队元,每个格子最多站1人,规定第一行,最后一行,第一列,最后一列必须站有队员。一共多少种方法。

这个题首先感觉是分类讨论,但是在计数的时候还是有些困难。那么从对立面开始思考呢?假如要求是第一行、列,最后一行、列不占人的话,那不就是很简单的C(x,y)的组合数问题了。

现在我们第一行不站拉拉队员的状态为A。最后一行不站拉拉队员的状态为B。第一列不站拉拉队员状态为C。最后一列不站拉拉队员的站立状态为D。

总情况为sum=C(m*n,k),根据容斥原理

那么我要的结果ans=sum-[(A+B+C+D)-(AB+AC+AD+AC+BC+BD+CD)+(ABC+ABD+BCD)-(ABCD)]

下面这个容斥原理怎样实现呢?用二进制表示ABCD 4个状态是否取到,sum->0,A->1,B->2,C->4,D->8,AC->3,ABCD->15。这样分成了16种状态

 #include <bits/stdc++.h>

 using namespace std;
#define M 505
const int mod =;
long long int c[M][M];
void init()//用递推公式来写组合数
{
memset(c,,sizeof c);
c[][]=;
for(int i=;i<M;++i)
{
c[i][]=c[i][i]=;
for (int j=;j<i;++j)
c[i][j]=(c[i-][j-]+c[i-][j])%mod;//注意取模
}
}
int main()
{
init();
int t;
scanf("%d",&t);
int casee=;
while (t--)
{
int n,m,k;
long long int sum=;
scanf("%d%d%d",&n,&m,&k);
for (int s=;s<;++s)
{
int r=n,c1=m,bin=;//bin来表示二进制状态
if (s&){r--;bin++;}
if (s&){r--;bin++;}
if (s&){c1--;bin++;}
if (s&){c1--;bin++;}
if (bin&)//激活状态为奇数
sum=(sum+mod-c[r*c1][k])%mod;//减法取模这样写
else
sum=(sum+c[r*c1][k])%mod;
}
printf("Case %d: ",++casee);
printf("%lld\n",sum);
}
return ;
}

UVa 11806 Cheerleaders (容斥原理+二进制表示状态)的更多相关文章

  1. UVA 11806 Cheerleaders (容斥原理)

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

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

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

  3. uva 11806 Cheerleaders

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

  4. UVA - 11806 Cheerleaders (容斥原理)

    题意:在N*M个方格中放K个点,要求第一行,第一列,最后一行,最后一列必须放,问有多少种方法. 分析: 1.集合A,B,C,D分别代表第一行,第一列,最后一行,最后一列放. 则这四行必须放=随便放C[ ...

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

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

  6. UVA 11806 Cheerleaders (容斥原理

    1.题意描述 本题大致意思是讲:给定一个广场,把它分为M行N列的正方形小框.现在给定有K个拉拉队员,每一个拉拉队员需要站在小框内进行表演.但是表演过程中有如下要求: (1)每一个小框只能站立一个拉拉队 ...

  7. UVa 11806 Cheerleaders (数论容斥原理)

    题意:给定一个n*m的棋盘,要放k个石子,要求第一行,最后一行,第一列,最后一列都有石子,问有多少种放法. 析:容斥原理,集合A是第一行没有石子,集合B是最后一行没有石子,集合C是第一列没有石子,集合 ...

  8. 【递推】【组合数】【容斥原理】UVA - 11806 - Cheerleaders

    http://www.cnblogs.com/khbcsu/p/4245943.html 本题如果直接枚举的话难度很大并且会无从下手.那么我们是否可以采取逆向思考的方法来解决问题呢?我们可以用总的情况 ...

  9. UVa 11806 - Cheerleaders (组合计数+容斥原理)

    <训练指南>p.108 #include <cstdio> #include <cstring> #include <cstdlib> using na ...

随机推荐

  1. mybatis源码分析之03SqlSession的创建

    在上一篇中,说到了mybatis是如何构造一个SqlSessionFactory实例的,顾名思意,SqlSessionFactory就是用于创建SqlSession的工厂类. 好,现在我们接着昨天的来 ...

  2. 三、PCB设计与Allegro基本概念

    PCB:印制电路板 如--update更新时无法变为0 4.区域规则--设置区域规则--赋予区域轮廓 5.铜皮 把.sav改为.dsn--就可以恢复出突然关闭的.dsn文件 生成规则钻孔文件(.drl ...

  3. [CSP-S模拟测试50]反思+题解

    ??大部分人都觉得T3是道不可做题去刚T1T2了,于是我就侥幸苟到了前面? 这场考试比较成功的就是快速水掉了T1T2的部分分,1h拿到88分起码为之后硬肝T3上了保险(赛后发现就算T3爆零也能rank ...

  4. python/pandas 正则表达式 re模块

    目录 正则解说 中文字符集 re模块常用方法 1.正则解说 数量词的贪婪模式与非贪婪模式 正则表达式通常用于在文本中查找匹配的字符串.Python里数量词默认是贪婪的(在少数语言里也可能是默认非贪婪) ...

  5. jenkins clone代码时间太长怎么办?

    在Jenkins的默认配置中,clone代码时会拉取所有历史版本的代码,而且默认的超时时限只有10分钟.这就造成在某些项目中,由于代码量本身就比较大,历史版本也比较多,再加上网络环境不是特别好,Jen ...

  6. Jenkins构建触发器的区别

    Build periodically:定时进行项目构建或执行(它不care源码是否发生变化),配置如下: 0 2 * * *  (每天2:00 必须build一次源码) 如果是要定时执行脚本,需要选择 ...

  7. vue2.0 项目小总结

    最近做了一个vue的PC端的项目,不大,真正用到vue的东西也不是太多,逻辑处理用到了不少原生js东西. 1.图片渲染 后台返回base64格式数据,一开始绑定src,提示pic字段未定义,懵逼了好久 ...

  8. python 装饰器 第五步(1):带有参数的装饰器

    #第五步:带有参数的装饰器 #用于扩展基本函数的函数 def kuozhan(func): #内部函数(扩展之后的eat函数) #5由于调用的时候传了两个参数,未来的eat函数没有参数接收 #5报错的 ...

  9. 精简Docker镜像的几个方法

    一.使用更精简的镜像 常用的Linux系统镜像一般有 Debian.Ubuntu.CentOS和Alpine,其中Alpine是面向安全的轻量级Linux发行版本.Docker的Alpine镜像仅有不 ...

  10. Loadrunner实现多台测试机负载时可能遇到的难题

    压测机安装的loadrunner版本为11.0 压测机器的操作系统是windows server 2016 所有的负载机器操作系统和压侧机器是一样的,都是windows server 2016 Err ...