UVA 10806 Cheerleaders

                      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[501][501];
const int mod = 1000007;

void run()
{

    unsigned long long ans = 0  , n  , m  , k ;
    cin >> n >> m >> k ;
    for( int s = 0 ; s < 16 ; ++s ){
        int b = 0 , r = n ,c = m ;
        if( s&1 ){ r-- ; b++ ;}
        if( s&2 ){ r-- ; b++ ;}
        if( s&4 ){ c-- ; b++ ;}
        if( s&8 ){ c-- ; b++ ;}
        if( b&1 ) 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 = 0 ; i <= 500 ; ++i ){
        C[i][0] = C[i][i] = 1 ;
        for( int j = 1 ; j < i ; ++j ){
            C[i][j] = ( C[i-1][j] + C[i-1][j-1] ) % mod ;
        }
    }
    int cas = 1 , _ ; cin >> _ ;
    while( _-- ) { cout << "Case "<< cas++ <<": "; run(); }
}

时间: 2024-11-19 06:14:34

UVA 10806 Cheerleaders的相关文章

UVA - 11806 - Cheerleaders (递推)

UVA - 11806 Cheerleaders Time Limit: 2000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description C Cheerleaders In most professional sporting events, cheerleaders play a major role in entertaining the spectators. Their roles a

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

uva 10806 Dijkstra, Dijkstra. 题目大意:你和你的伙伴想要越狱.你的伙伴先去探路,等你的伙伴到火车站后,他会打电话给你(电话是藏在蛋糕里带进来的),然后你就能够跑去火车站了,那里有人接应你. 可是.由于你的伙伴跑去火车站的时候穿的是囚服,所以,他经过的街道都被戒严了,你必须从其它街道跑过去. 假设你能够到达火车站,请输出你和你的伙伴在路上花费的最短时间,假设不能请"Back to jail". 解题思路:最小费最大流.设置一个超级源点连向监狱(起点1), 容

uva 11806 - Cheerleaders(容斥原理)

题目链接:uva 11806 - Cheerleaders 题目大意:在一个m行n列的矩阵网里放k个石子,问有多少种画法?每个格子最多放一个石子,所有石子必须用完,并且在第一行.最后一行.第一列和最后一列都得有石子. 解题思路:容斥原理,我们可以先求说在m?n的矩阵上放k个石子的种数C(nmk),减掉四条边界不放的情况就是答案了.所以枚举16种状态,用二进制数表示说四条边中那些边是不放石子的. 代码 #include <cstdio> #include <cstring> cons

UVA 11806 - Cheerleaders(数论+容斥原理)

题目链接:11806 - Cheerleaders 题意:在一个棋盘上,要求四周的四行必须有旗子,问有几种摆法. 思路:直接算很容易乱掉,利用容斥原理,可知AUBUCUD = |A| + |B| + |C| + |D| - |AB| - |BC| - |AC| - |AD| - |BD| - |CD| + |ABC| + |ABD| + |ACD| + |BCD| - |ABCD| 由此利用位运算去计算即可 代码: #include <stdio.h> #include <string.

UVa 10806 Dijkstra, Dijkstra (最小费用流)

Dijkstra, Dijkstra Dexter: “You don’t understand. I can’t walk... they’ve tied my shoelaces together.” Topper Harley: “A knot. Bastards!” Jim Abrahams and Pat Proft, "Hot Shots! Part Deu Description you are a political prisoner in jail. Things are lo

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

题目链接:https://uva.onlinejudge.org/external/108/10806.pdf 题意:无向图,从1到n来回的最短路,不走重复路. 分析:可以考虑为1到n的流量为2时的最小花费: 建图: 一个点到一个点的容量为1,费用为距离. 1 #include <cstring> 2 #include <cstdio> 3 #include <vector> 4 #include <queue> 5 #include <algorit

UVa 11806 Cheerleaders

题意:m行n列的矩形网格放k个相同的石子,要求第一行最后一行第一列最后一列都必须有石子,问有多少种放法 A为第一行没有石子的方案数,BCD依此类推,全集为S 如果没有任何要求的话,放法数应该是C(rc, k) 解法中利用容斥原理来解 所求的方案就是在S中但不在ABCD中任何一个的方案即:S - |A∪B∪C∪D| 而|A∪B∪C∪D| = |A| + |B| + |C| + |D| - |A∩B| - |A∩C| - |A∩D| - |B∩C| - |B∩D| - |C∩D| + |A∩B∩C|

【递推】【组合数】【容斥原理】UVA - 11806 - Cheerleaders

http://www.cnblogs.com/khbcsu/p/4245943.html 本题如果直接枚举的话难度很大并且会无从下手.那么我们是否可以采取逆向思考的方法来解决问题呢?我们可以用总的情况把不符合要求的减掉就行了. 首先我们如果不考虑任何约束条件,我们可以得出如下结论:                                                                       下载我们假定第一行不站拉拉队员的所有的站立方法有A种.最后一行不站拉拉队员的

uva 11806 - Cheerleaders(容斥原理+二进制)

题目链接点击打开链接 题意: n行m列网格放k个石子.有多少种方法?要求第一行,第一列,最后一行,最后一列必须有石子. 思路: 1.利用容斥原理的拓展 假设有三个集合 S 另有三个集合A B C,不属于 A.B.C任何一个集合,但属于全集S的元素, 奇数个减:偶数个加 此处是S为空集  A.B.C.D分别代表 行 列中的四种情况: AUBUCUD = |A| + |B| + |C| + |D| - |AB| - |BC| - |AC| - |AD| - |BD| - |CD| + |ABC| +