UVA 10806 Cheerleaders
|
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 modulo1000007.
|
Sample Input |
Sample Output |
|
2 2 2 1 2 3 2 |
Case 1: 0 Case 2: 2
|
k个石头放到 n*m 的矩阵 , 在4条边上一定要有石头有多少种方法 ?
用容斥来加加减减...
集合A表示第一行没石头...集合B表示第二行没有石头.. D..C如痴类推。
0 ~ 1<<16-1 表示出所有集合..
当我们加上全集的时候,,,要剪一个除了A的集合,,,但是少剪了除了B的集合..
若果剪了除了B的集合...我们多减了同时出去A.B情况的集合..这个时候要加回来..
思想大概如此
#include <bits/stdc++.h>
using namespace std;
unsigned long long C[][];
const int mod = ; void run()
{ unsigned long long ans = , n , m , k ;
cin >> n >> m >> k ;
for( int s = ; s < ; ++s ){
int b = , r = n ,c = m ;
if( s& ){ r-- ; b++ ;}
if( s& ){ r-- ; b++ ;}
if( s& ){ c-- ; b++ ;}
if( s& ){ c-- ; b++ ;}
if( b& ) ans = ( ans + mod - C[r*c][k] ) %mod ;
else ans = ( ans + C[r*c][k] )%mod;
}
cout << ans << endl;
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
for( int i = ; i <= ; ++i ){
C[i][] = C[i][i] = ;
for( int j = ; j < i ; ++j ){
C[i][j] = ( C[i-][j] + C[i-][j-] ) % mod ;
}
}
int cas = , _ ; cin >> _ ;
while( _-- ) { cout << "Case "<< cas++ <<": "; run(); }
}
UVA 10806 Cheerleaders的更多相关文章
- uva 11806 Cheerleaders
// uva 11806 Cheerleaders // // 题目大意: // // 给你n * m的矩形格子,要求放k个相同的石子,使得矩形的第一行 // 第一列,最后一行,最后一列都必须有石子. ...
- UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)
UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举) 题意分析 给出n*m的矩形格子,给出k个点,每个格子里面可以放一个点.现在要求格子的最外围一圈的每行每列,至少要放一个 ...
- uva 10806 Dijkstra, Dijkstra. (最小费最大流)
uva 10806 Dijkstra, Dijkstra. 题目大意:你和你的伙伴想要越狱.你的伙伴先去探路,等你的伙伴到火车站后,他会打电话给你(电话是藏在蛋糕里带进来的),然后你就能够跑去火车站了 ...
- Uva 10806 来回最短路,不重复,MCMF
题目链接:https://uva.onlinejudge.org/external/108/10806.pdf 题意:无向图,从1到n来回的最短路,不走重复路. 分析:可以考虑为1到n的流量为2时的最 ...
- UVA 11806 Cheerleaders dp+容斥
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
- UVa 11806 Cheerleaders (容斥原理+二进制表示状态)
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
- uva 11806 Cheerleaders (容斥)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 10806 & 费用流+意识流...
题意: 一张无向图,求两条没有重复的从S到T的路径. SOL: 网络流为什么屌呢..因为网络流的容量,流量,费用能对许许多多的问题进行相应的转化,然后它就非常的屌. 对于这道题呢,不是要没有重复吗?不 ...
- UVA 11806 Cheerleaders (组合+容斥原理)
自己写的代码: #include <iostream> #include <stdio.h> #include <string.h> /* 题意:相当于在一个m*n ...
随机推荐
- 如何判断索引是否生效--explain
explain 显示了MySql 如何使用索引来处理select语句以及连接表. 使用方式在select 前面加上 explain就可以了 示例:explain select id , name ta ...
- BZOJ 4524(贪心+二叉堆)
题面 若一个大于 11 的整数 M的质因数分解有 k 项,其最大的质因子为 \(a_k\),并且满足 \({a_k}^k \leq N,k<128\),我们就称整数 M 为 N-伪光滑数. 现在 ...
- CentOS使用手册(一)
前言:全栈开发当然少不了服务器的配置与维护,本次打算参考网上资料和大地老师的视频写一个CentOS系列的手册,方便日后查阅. 本篇目录: 1.虚拟机上的CentOS基本安装流程 2.远程连接Linux ...
- 【牛客网-剑指offer】矩形覆盖
题目: 我们可以用21的小矩形横着或者竖着去覆盖更大的矩形.请问用n个21的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 分析: 假设2为高,n为宽 因为高为2固定,会出现固定情况,即无论 ...
- WPF 基本图形
一.WPF的基本图形 WPF图形的基类是Shape,所有的wpf图形类都是继承于Shape.Height,Width等决定它所处的面积,位置等,在没有设置图形宽高的情况,坐标位置为所在的容器的坐标,设 ...
- Codeforces 360E 贪心 最短路
题意及思路:https://blog.csdn.net/huanghongxun/article/details/49846927 在假设所有边都是最大值的情况下,如果第一个人能比第二个人先到,那就缩 ...
- GOOSE报文解析
GOOSE报文解析 变电站 使用 MMS报文 http://www.360doc.com/content/16/1014/20/36538220_598459873.shtml
- java基础之轻松搞定反射
前言 java的名词太古怪.反射白话文解释,就是把一个字符串的类名,实例化,少了个new单词. 反射步骤 准备一个苹果类像这个样子. public class PingGuo { private St ...
- Java 枚举和类的区别
枚举 包含一组常量合法的数据,不能创建枚举实例,也不能进行扩展. package com.jtfr.demo; public enum Week { MONDAY, TUESDAY, WEDNESDA ...
- Spring MVC processing flow
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11484057.html DispatcherServlet receives the request. ...