UVa11806 Cheerleaders(容斥原理)
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(容斥原理)的更多相关文章
- 【UVA11806 Cheerleaders】 题解
题目链接:https://www.luogu.org/problemnew/show/UVA11806 容斥原理+组合数 正着找合♂fa的不好找,那就用总方案数-不合♂fa的 #include < ...
- UVA 11806 Cheerleaders (容斥原理)
题意 一个n*m的区域内,放k个啦啦队员,第一行,最后一行,第一列,最后一列一定要放,一共有多少种方法. 思路 设A1表示第一行放,A2表示最后一行放,A3表示第一列放,A4表示最后一列放,则要求|A ...
- UVA11806 Cheerleaders
题意 PDF 分析 如果要求是某行某列没有石子很好算,就一个组合数. 然后要求某行某列有,就用容斥原理就行了. 时间复杂度\(O(k^2 + 16T)\) 代码 #include<iostrea ...
- UVA-11806 Cheerleaders 计数问题 容斥定理
题目链接:https://cn.vjudge.net/problem/UVA-11806 题意 在一个mn的矩形网格里放k个石子,问有多少方法. 每个格子只能放一个石头,每个石头都要放,且第一行.最后 ...
- UVA11806 Cheerleaders (容斥)
题目链接 Solution 可以考虑到总方案即为 \(C_{nm}^k\) . 考虑到要求的是边缘都必须至少有 \(1\) ,所以考虑不合法的. 第一行和最后一行没有的方案即为 \(C_{(n-1)m ...
- UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)
UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举) 题意分析 给出n*m的矩形格子,给出k个点,每个格子里面可以放一个点.现在要求格子的最外围一圈的每行每列,至少要放一个 ...
- uva11806(容斥原理)
11806 - Cheerleaders Time limit: 2.000 seconds In most professional sporting events, cheerleaders pl ...
- UVa 11806 Cheerleaders (容斥原理+二进制表示状态)
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
- UVA 11806 Cheerleaders (组合+容斥原理)
自己写的代码: #include <iostream> #include <stdio.h> #include <string.h> /* 题意:相当于在一个m*n ...
随机推荐
- tp3.2 页面Windows正常 linux异常,页面找不到
这个问题主要是tp3.2 在读取控制器里的方法时,会把方法自动转为小写, 然后去对应view成找html文件,自然找不到. class textController extends ComContro ...
- NDK下编译JNI
NDK环境下编译JNI 下载demo.tar.gz然后解压 弄个套路 1.编辑build.sh设置好NDK目录 2.把cpp文件放到code下面 运行sh build.sh即可
- EasyHook
EasyHook实用指南 所谓实用指南就是全是干货,没那么多虚头巴脑的东西,真正要用的人会发现对自己有用的东西,浅尝辄止的人看起来会不知所云. FileMon自己实做的过程中遇到的问题: 1. exe ...
- 后台以json数据形式返回之后前台接受的方法以及之后的解析总结
1.前台AJAX请求,后台以对象转JSON形式返回: 后台代码: @RequestMapping(value = "/queryDist", method = RequestMet ...
- linux配置ssh公钥认证,打通root用户的免密码输入的scp通道
1.ssh-keygen ssh-keygen是unix-like系统的一个用来生成.管理ssh公钥和私钥的工具. 2.用法 常用的重要的选项有: -b num 指定生成多少比特长度的key,单位 ...
- ASP.NET对路径"C:/......."的访问被拒绝 解决方法小结 [转载]
问题: 异常详细信息: System.UnauthorizedAccessException: 对路径“C:/Supermarket/output.pdf”的访问被拒绝. 解决方法: 一.在IIS中的 ...
- 阶段3 1.Mybatis_02.Mybatis入门案例_3.mybatis注解开发和编写dao实现类的方式
注解的用法 直接创建一个新的项目 下一步直接next 然后finish即可 把之前项目01里面的代码直接复制过来 复制到我们02的注解的工程中 把01项目导入的依赖也都粘贴过来 再把测试类复制过去 复 ...
- windows 下使用Linux子系统
在 Windows 上进行 web 开发,比较普遍的方案是使用 phpstudy 或者别的一些集成环境软件进行环境搭建,写好代码后将代码上传至版本管理工具 git/svn,再将代码同步到 Linux ...
- 【笔记】云主机当跳板,ssh tunnel远程登录树莓派
问题 想要在外网登录家中局域网的树莓派,家里的网络外网ip的会变,而且不适合对公网暴露端口.调研了一番,发现可以使用云主机当跳板,结合ssh隧道实现远程登录到局域网中的树莓派 关于ssh隧道的原理可以 ...
- 001-Django简介与项目创建
简介 django,是用python语言写的开源web开发框架,并遵循MVC设计 主要目的是简便.快速的开发数据库驱动的网站 强调代码复用,有很多第三方插件,强调快速开发和DRY(DoNotRepea ...