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. java 根据省份证号-判断省份-性别-生日

    package com.nf147.manage.Test; import java.text.ParseException; import java.text.SimpleDateFormat; i ...

  2. docker部署Javaweb项目(jdk+tomcat+mysql)

    步骤一:在主机下载安装docker,参照Centos7上安装docker 步骤二:下载Linux版本的JDK1.6和Tomcat6.0(其他项目若依赖其他版本的运行环境可选择另外版本下载),通过sec ...

  3. MyBaits动态sql语句

    1 在接口中书写方法 public interface EmployeeMapperDynamicSQL { public List<Employee> getEmpsTestInnerP ...

  4. ef和ashx的简单测试

    在这里.小弟我默默的计算了一下用一般处理程序和MVC配合EF,到底哪个快,事实问题是我感觉都差不多,因为用的是EF,所以要提高访问速率,我觉得还是要从数据访问做起: 一般处理程序代码: private ...

  5. ES6数组的拓展

    扩展运算符 扩展运算符(spread)是三个点(...).它好比 rest 参数的逆运算,将一个数组转为用逗号分隔的参数序列. console.log(...[1, 2, 3]) // 1 2 3 c ...

  6. 转]@SuppressWarnings 详解

    转自:http://gladto.iteye.com/blog/728634 背景知识:        从JDK5开始提供名为Annotation(注释)的功能,它被定义为JSR-175规范.注释是以 ...

  7. 关于自定义 List集合排序的方法!

    大致流程: 排序是用到排序的接口Comparator<T>你要先建一个类实现比较器Comparator //大致流程public class StuComp implements Comp ...

  8. 用 Python 解答两道来自阿里伯乐系统的笔试题

    目录 目录 前言 题目一 分析 实现 题目二 分析 实现 前言 朋友到阿里面试,分享两道小题,博主比较闲就试着用 Python 解答一下,实现方式肯定是多种多样的,优劣也会各有不同,欢迎交流. 题目一 ...

  9. Eclipse与Tomcat

    新进一个Web项目,有些小坎坷,于是引发了对于Eclipse和Tomcat的配置关系的思考. 首先提及一点当年的观点:Tomcat是一个容器,所有的功能都是以插件的形式放入其中:比如tomcat就是o ...

  10. linux 学习笔记一

    Linux 学习笔记一 计算机 主要分为五个部分:控制器,运算器,存储器,输入设备,输出设备. 操作系统 操作系统就是针对硬件编写的程序,同时提供硬件接口调用的接口.操作系统需要处理如管理与配置内存. ...