11806 - Cheerleaders

Time limit: 2.000 seconds

C 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 Sample Output 2 2 2 1 2 3 2 Case 1: 0 Case 2: 2

//本题利用容斥原理:S为全集!!

A表示第一行没有石子;B表示第n行没有石子;C表示第一列没有石子;D表示第n列没有石子;

则A∪B∪C∪D=S;

则S=(A+B+C+D)-(_∩_)+(_∩__∩_)-(_∩__∩__∩_); //

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll; const int mo=;
const int M=; int C[M][M];
void yanghui()
{
int i,j;
C[][]=C[][]=C[][]=;
for(i=;i<M;i++)
{
C[i][]=C[i][i]=;
for(j=;j<i;j++)
C[i][j]=(C[i-][j-]+C[i-][j])%mo;
}
} int main()
{
yanghui();
int st,ca,k,m,n,T,i;
scanf("%d",&T);
for(ca=;ca<=T;ca++)
{
scanf("%d%d%d",&n,&m,&k);
printf("Case %d: ",ca);
if(k>n*m){printf("0\n");continue;}
int s=C[n*m][k];
for(st=;st<;st++)//枚举状态
{
int b=,r=n,c=m;//b统计集合的个数,r和c统计可以防止的行列数!!!
if(st&){b++;r--;};
if(st&){b++;r--;};
if(st&){b++;c--;};
if(st&){b++;c--;};
if(b&)s=(s-C[r*c][k]+mo)%mo;
else s=(s+C[r*c][k])%mo;
}
printf("%d\n",s);
}
return ;
}

UVa11806 Cheerleaders(容斥原理)的更多相关文章

  1. 【UVA11806 Cheerleaders】 题解

    题目链接:https://www.luogu.org/problemnew/show/UVA11806 容斥原理+组合数 正着找合♂fa的不好找,那就用总方案数-不合♂fa的 #include < ...

  2. UVA 11806 Cheerleaders (容斥原理)

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

  3. UVA11806 Cheerleaders

    题意 PDF 分析 如果要求是某行某列没有石子很好算,就一个组合数. 然后要求某行某列有,就用容斥原理就行了. 时间复杂度\(O(k^2 + 16T)\) 代码 #include<iostrea ...

  4. UVA-11806 Cheerleaders 计数问题 容斥定理

    题目链接:https://cn.vjudge.net/problem/UVA-11806 题意 在一个mn的矩形网格里放k个石子,问有多少方法. 每个格子只能放一个石头,每个石头都要放,且第一行.最后 ...

  5. UVA11806 Cheerleaders (容斥)

    题目链接 Solution 可以考虑到总方案即为 \(C_{nm}^k\) . 考虑到要求的是边缘都必须至少有 \(1\) ,所以考虑不合法的. 第一行和最后一行没有的方案即为 \(C_{(n-1)m ...

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

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

  7. uva11806(容斥原理)

    11806 - Cheerleaders Time limit: 2.000 seconds In most professional sporting events, cheerleaders pl ...

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

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

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

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

随机推荐

  1. Mac ssh key生成

    转载https://blog.csdn.net/wangjunling888/article/details/51115659 1. 查看秘钥是否存在 打开终端查看是否已经存在SSH密钥:cd ~/. ...

  2. C++嵌入lua

    需要在C++程序里面嵌入lua 下面是代码,怕忘记,记录一下 #include <stdio.h> #include <stdlib.h> extern "C&quo ...

  3. linux fedora原生的快捷键操作

    显示桌面: ctrl+alt+d 运行终端程序: gnome-terminal : 可以自定义快捷键: ctrl+T 等等.

  4. svn访问版本库时一直提示: please wait while the repository browser is initializing

    最近不知道做了什么操作,原来正常的SVN Check In/Out都无法正常操作. 正常Check In的动作,几秒钟就会操作完成,但是我却等了好久好久,然后提示Connection timed ou ...

  5. 【Appium遇到的坑】环境配置无误,路径无中文,无空格,提示error: Logcat capture failed: spawn ENOENT

    代码如下,提示error: Logcat capture failed: spawn ENOENT from appium import webdriver from time import slee ...

  6. Chapter03 第四节 c++的算术运算符

    c++算术运算符 3.4.1 运算符的优先级和结合性 四则运算参考四则运算优先级,注意括号. 3.4.2 除法的默认类型转换和精度问题 /* * @Description: 除法 * @Author: ...

  7. 20191128 Spring Boot官方文档学习(9.4-9.8)

    9.4.Spring MVC Spring Boot有许多启动器包含Spring MVC.请注意,一些启动器包括对Spring MVC的依赖,而不是直接包含它. 9.4.1.编写JSON REST服务 ...

  8. APIView的流程分析

     APIView的流程分析 1.入口,因为视图类的继承APIView()的 as_view()是一个绑定类的方法 2.进入as_view(),正好这个as_view()有个返回值 返回的是dispat ...

  9. 解读Nodejs多核处理模块cluste

    http://blog.fens.me/nodejs-core-cluster/ Node.js开发框架Express4.x   http://blog.fens.me/nodejs-express4 ...

  10. 文档压缩 | gzip、bzip2、xz

    6.文档的压缩与打包 Linux下常见后缀名所对应的的压缩工具 .gz 表示由gzip压缩工具压缩的文件 .bz2 表示由bzip2压缩工具压缩的文件 .tar 表示由tar打包程序打包的文件(tar ...