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 ...
随机推荐
- Python 学习笔记12 函数模块
函数的优点之一,使用它们可将代码块与主程序分离.通过给函数指定描述性的名称.可以让主程序非常好理解.但是如果将过多的函数和主程序放置在一起,会让文件显得非常凌乱.太多的代码混杂在一起,不方便管理.我们 ...
- leetcode.图.207课程表-Java
1. 具体题目 现在你总共有 n 门课需要选,记为 0 到 n-1.在选修某些课程之前需要一些先修课程. 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1].给定 ...
- leetcode.双指针.680验证回文字符串-Java
1. 具体题目 给定一个非空字符串 s,最多删除一个字符.判断是否能成为回文字符串. 示例 1: 输入: "aba" 输出: True 示例 2: 输入: "abca&q ...
- json模块 pickle 模块 collections 模块 openpyxl 模块
json模块 json 模块是一个系列化模块 一个第三方的特殊数据格式 可以将python数据类型----> json 数据格式 ----> 字符串 ----> 文件 其他语言想要使 ...
- leetcde-27-移除元素
问题: package com.example.demo; public class Test27 { /** * 定义一个尾指针,该位置放置和val不同的元素, * 遍历数组,将不同的元素全部放置到 ...
- 小议ArcMap面转线的几种方式
ArcMap是一个功能丰富的复杂系统,但凡对它有些认知的会同意这个观点. 它的丰富与复杂体现在一个objective有多种implementation,还体现在多种implementation有类似的 ...
- nginx方向代理详解及配置
一代理服务器1.代理服务器,客户机在发送请求时,不会直接发送给目的主机,而是先发送代理服务器,代理服务器接受客户机请求之后,在向主机发出,并接受目的主机返回的数据,存放在代开服务器的硬盘中,在发送给客 ...
- 六、hibernate表与表之间的关系(多对多关系)
多对多关系 创建实体类和对应映射文件 Student.java package com.qf.entity; import java.util.HashSet; import java.util.Se ...
- java 多线程实现的四种方式
一个线程的生命周期 线程是一个动态执行的过程,它也有一个从产生到死亡的过程. 下图显示了一个线程完整的生命周期. 新建状态: 使用 new 关键字和 Thread 类或其子类建立一个线程对象后,该线程 ...
- for循环(foreach型)举例