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 ...
随机推荐
- POJ 1625 Censored ( Trie图 && DP && 高精度 )
题意 : 给出 n 个单词组成的字符集 以及 p 个非法串,问你用字符集里面的单词构造长度为 m 的单词的方案数有多少种? 分析 :先构造出 Trie 图方便进行状态转移,这与在 POJ 2278 中 ...
- 卡死浏览器使IPhone的自带safari打开重启的JS循环代码
<html> <body> <script> var total=""; for (var i=0; i < 1000000; i++) ...
- Hibernate一级缓存之懒加载问题
Hibernate的懒加载: 当用到数据的时候才向数据库查询,这就是hibernate的懒加载特性. 目的,为提高程序执行效率. 查询操作:get()方法/load()方法 (1)get()方法,及时 ...
- Vue创建全局组件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue的组件通讯 父传子 -- 子传父-- 兄弟组件的传值 vue的组件传值
首先文字简单撸一下 父子传子 -------首先在父组件上绑定一个属性,在子组件里用props接收,可以是数组或者是对象 子传父 ------在父组件升上自定义一个方法,在子组件里通过this ...
- (转)深入理解Java:注解(Annotation)自定义注解入门
向作者致敬! 转自:http://www.cnblogs.com/peida/archive/2013/04/24/3036689.html 要深入学习注解,我们就必须能定义自己的注解,并使用注解,在 ...
- postman通过引入外部文件实现参数化
postman可通过引入外部文件进行参数化 目录 1.准备好接口信息 2.设置 1.准备好接口信息 这里的usr和psw是要参数化的对象 2.设置 文件准备 添加文件,并设置好循环次数即可
- Cloudera-JDBC-Driver-for-Impala
Cloudera-JDBC-Driver-for-Impala-Install-Guide-2-5-5.pdf https://github.com/FlowerBirds/flowerbirds.g ...
- 如何比较两个txt文件内容的细微差别
如何比较两个txt文件内容的细微差别 https://jingyan.baidu.com/article/19020a0a1dd04a529c284272.html 听语音 | 浏览:3500 | 更 ...
- Linux中MySQL5.7设置utf8编码格式步骤
关于编码问题,真的是弄得我很郁闷,网上找的帖子这方面也很多但都无济于事,晚上终于找到一篇有效的,特此贴上. 转自Ubuntu中MySQL5.7设置utf8编码格式步骤 1.首先打开终端 2.输入mys ...