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. Linux小记 -- [已解决]Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings

    问题描述 操作系统:Ubuntu Server 18.04 LTS Ubuntu每次启动时产生如下motd(message of today)输出 Failed to connect to https ...

  2. 第一次试验报告&学习总结

    打印输出所有的"水仙花数",所谓"水仙花数"是指一个3位数,其中各位数字立方和等于该数本身.例如,153是一个"水仙花数". 试验代码: p ...

  3. jQuery.parseJSON()

    https://api.jquery.com/jQuery.parseJSON/ https://api.jquery.com/category/deprecated/deprecated-3.0/ ...

  4. DeepFaceLab报错,integer division or modulo by zero

    DeepFaceLab的集成环境在众多换脸软件中是做的最好的.但是使用过程也会出现一些错误,主要的错误有两个,一个是你配置太低OOM了,主要体现显存太低.第二个是版本不对应.比如你原先用的cuda9. ...

  5. CANopen的相关学习

    CANopen是一种架构在控制局域网路(Controller Area Network, CAN)上的高层通讯协定,包括通讯子协定及设备子协定常在嵌入式系统中使用,也是工业控制常用到的一种现场总线. ...

  6. Spring 缓存注解解析过程

    Spring 缓存注解解析过程 通过 SpringCacheAnnotationParser 的 parseCacheAnnotations 方法解析指定方法或类上的缓存注解, @Cacheable ...

  7. day64—ajax技术学习笔记

    转行学开发,代码100天——2018-05-19 Ajax技术学习笔记 AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML).AJA ...

  8. apache-httpd2.4编译安装

    centos 6 编译安装httpd-2.4 centos6yum安装的apr版本已经不适用httpd-2.4版本了.所以,需要源码编译apr以及apr-util1. 下载源码:cd /usr/loc ...

  9. Jmeter测试HTTP接口

    一.工具说明 Jmeter是一款开源的桌面应用软件,可以用于进行接口测试和性能测试.因为该软件是开源的,所以更具扩展性.Jmeter可以对Web应用进行测试,另外还支持Java请求.Webservic ...

  10. pycharm运行正确但是不出结果

    描述:之前用的好好的,突然有一天用pycharm运行程序,明明结果正确, 打印不出来结果,看下图 解决: 查看File Transfer有好多错误,意思是没有连接上服务器 [2018/12/8 21: ...