Cheerleaders
Description
 

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的更多相关文章

  1. uva 11806 Cheerleaders

    // uva 11806 Cheerleaders // // 题目大意: // // 给你n * m的矩形格子,要求放k个相同的石子,使得矩形的第一行 // 第一列,最后一行,最后一列都必须有石子. ...

  2. UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)

    UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举) 题意分析 给出n*m的矩形格子,给出k个点,每个格子里面可以放一个点.现在要求格子的最外围一圈的每行每列,至少要放一个 ...

  3. uva 10806 Dijkstra, Dijkstra. (最小费最大流)

    uva 10806 Dijkstra, Dijkstra. 题目大意:你和你的伙伴想要越狱.你的伙伴先去探路,等你的伙伴到火车站后,他会打电话给你(电话是藏在蛋糕里带进来的),然后你就能够跑去火车站了 ...

  4. Uva 10806 来回最短路,不重复,MCMF

    题目链接:https://uva.onlinejudge.org/external/108/10806.pdf 题意:无向图,从1到n来回的最短路,不走重复路. 分析:可以考虑为1到n的流量为2时的最 ...

  5. UVA 11806 Cheerleaders dp+容斥

    In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...

  6. UVa 11806 Cheerleaders (容斥原理+二进制表示状态)

    In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...

  7. uva 11806 Cheerleaders (容斥)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. UVa 10806 & 费用流+意识流...

    题意: 一张无向图,求两条没有重复的从S到T的路径. SOL: 网络流为什么屌呢..因为网络流的容量,流量,费用能对许许多多的问题进行相应的转化,然后它就非常的屌. 对于这道题呢,不是要没有重复吗?不 ...

  9. UVA 11806 Cheerleaders (组合+容斥原理)

    自己写的代码: #include <iostream> #include <stdio.h> #include <string.h> /* 题意:相当于在一个m*n ...

随机推荐

  1. 不小心执行了 rm -f,先别急着跑路

    作者:justmine http://www.cnblogs.com/justmine/p/10359186.html 前言 每当我们在生产环境服务器上执行rm命令时,总是提心吊胆的,因为一不小心执行 ...

  2. Spring Cloud 使用Spring Cloud Loadbalancer访问服务地址

    获取服务地址 使用的EurekaClient : getNextServerFromEureka() 使用的DiscoveryClient: getInstances() Load Balancer ...

  3. Flask+elasticsearch实现搜索引擎入门教程+Curl调试

    前几天,在github上看到了一个关于elasticsearch的小项目,有点小兴趣,于是就结合着Flask,研究了一下,分享给大家. 准备资料: 1.安装elasticsearch 参考教程:htt ...

  4. Flask-Login的实现

    Flask-Login Flask-Login 为 Flask 提供用户 session 的管理机制.它可以处理 Login.Logout 和 session 等服务. 作用: 将用户的 id 储存在 ...

  5. jvm加载包名和类名相同的类的规则,以及如何加载包名和类名相同的类(转)

    jvm包括三种类加载器: 第一种:bootstrap classloader:加载java的核心类. 第二种:extension classloader:负责加载jre的扩展目录中的jar包. 第三种 ...

  6. shell 中| 用法

    | 运算符 管道符号,是unix一个很强大的功能,符号为一条竖线:"|".用法: command 1 | command 2 他的功能是把第一个命令command 1执行的结果作为 ...

  7. python 环境准备-centos7

    python3环境搭建[本身centosyum底层也是py2.x实现的,装3.x的时候要实现多版本共存这里解决了这些问题] 安装编译环境# yum -y groupinstall 'Developme ...

  8. php结合Redis实现100万用户投票项目,并实时查看到投票情况的案例

    场景:某网站需要对其项目做一个投票系统,投票项目上线后一小时之内预计有100万用户进行投票,希望用户投票完就能看到实时的投票情况 这个场景可以使用redis+mysql冷热数据交换来解决. 何为冷热数 ...

  9. 洛谷P2015 二叉苹果树(树状dp)

    题目描述 有一棵苹果树,如果树枝有分叉,一定是分2叉(就是说没有只有1个儿子的结点) 这棵树共有N个结点(叶子点或者树枝分叉点),编号为1-N,树根编号一定是1. 我们用一根树枝两端连接的结点的编号来 ...

  10. 【HDOJ6581】Vacation(模拟)

    题意:有标号从0到n的n+1辆车,每辆车离终点的距离为s[i],车长为l[i],速度为v[i],规定不能超车,问何时所有车都能过终点线 n<=1e5,保证 思路: #include<bit ...