题意:给定一个n*m的棋盘,要放k个石子,要求第一行,最后一行,第一列,最后一列都有石子,问有多少种放法。

析:容斥原理,集合A是第一行没有石子,集合B是最后一行没有石子,集合C是第一列没有石子,集合D是最后一列没有石子,如果某一行或某一列,

没有,那么就相当于减少一行或者一列。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <ctime>
#include <cstdlib>
#define debug puts("+++++")
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 500 + 5;
const LL mod = 1000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
inline int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
inline int lcm(int a, int b){ return a * b / gcd(a, b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
LL C[maxn][maxn]; void init(){
for(int i = 0; i < maxn; ++i) C[i][i] = C[i][0] = 1;
for(int i = 1; i < maxn; ++i)
for(int j = 1; j <= i; ++j)
C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
} int main(){
init();
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
int k;
scanf("%d %d %d", &n, &m, &k);
int ans = 0;
for(int i = 0; i < 16; ++i){
bool ok = true;
int r = n, c = m;
if(i & 1){ ok = !ok; --r; }
if(i & 2){ ok = !ok; --r; }
if(i & 4){ ok = !ok; --c; }
if(i & 8){ ok = !ok; --c; }
if(ok) ans = (ans + C[r*c][k]) % mod;
else ans = (ans - C[r*c][k] + mod) % mod;
}
printf("Case %d: %d\n", kase, ans);
}
return 0;
}

UVa 11806 Cheerleaders (数论容斥原理)的更多相关文章

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

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

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

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

  3. UVA 11806 Cheerleaders (容斥原理

    1.题意描述 本题大致意思是讲:给定一个广场,把它分为M行N列的正方形小框.现在给定有K个拉拉队员,每一个拉拉队员需要站在小框内进行表演.但是表演过程中有如下要求: (1)每一个小框只能站立一个拉拉队 ...

  4. UVA - 11806 Cheerleaders (容斥原理)

    题意:在N*M个方格中放K个点,要求第一行,第一列,最后一行,最后一列必须放,问有多少种方法. 分析: 1.集合A,B,C,D分别代表第一行,第一列,最后一行,最后一列放. 则这四行必须放=随便放C[ ...

  5. uva 11806 Cheerleaders

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

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

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

  7. UVA 11806 Cheerleaders (容斥原理)

    题意 一个n*m的区域内,放k个啦啦队员,第一行,最后一行,第一列,最后一列一定要放,一共有多少种方法. 思路 设A1表示第一行放,A2表示最后一行放,A3表示第一列放,A4表示最后一列放,则要求|A ...

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

    http://www.cnblogs.com/khbcsu/p/4245943.html 本题如果直接枚举的话难度很大并且会无从下手.那么我们是否可以采取逆向思考的方法来解决问题呢?我们可以用总的情况 ...

  9. UVa 11806 - Cheerleaders (组合计数+容斥原理)

    <训练指南>p.108 #include <cstdio> #include <cstring> #include <cstdlib> using na ...

随机推荐

  1. 【BZOJ1492】货币兑换Cash(CDQ分治)

    题意: 小 Y 最近在一家金券交易所工作.该金券交易所只发行交易两种金券:A 纪 念券(以下简称 A 券)和 B 纪念券(以下简称 B 券).每个持有金券的顾客都有 一个自己的帐户.金券的数目可以是一 ...

  2. Heredoc和Nowdoc

    就象heredoc结构类似于双引号字符串,Nowdoc结构是类似于单引号字符串的.Nowdoc结构很象heredoc结构,但是 nowdoc不进行解析操作 . 这种结构很适合用在不需要进行转义的PHP ...

  3. BUPT2017 springtraining(16) #1 题解

    https://vjudge.net/contest/162590 A: 不难发现,当L=R时输出L,当L<R时输出2. B: 贪心得配对.1和n配 2和n-1配,对与对直接只要花1个代价就可以 ...

  4. Log4j的日志级别分析(转)

    说明:Log4j的日志是有级别的,从低到高顺序为:ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF,当定义了日志级别为 ...

  5. 虚拟社会(Virtual Society)

    虚拟社会(Virtual Society),又称赛博社会(Cyber Society),是指不同网民之间经由计算机.远程通讯终端等技术设备相互连接起来以进行信息的共享.互动与交流,并在其中进行社会交往 ...

  6. App中显示html网页

    在现在的移动开发中,越来越多的web元素增加到了app里面,hybrid app可以综合native app 和 web app的长处,可以通过webView实现 htmllayout.xml: &l ...

  7. ZXing-core生成二维码和解析

    如今二维码这么流行的时刻.也必须知道二维码是怎么生成.如今我们就来看看,是怎么生成的. 事实上主要是利用goggle公布的jar来使用:本文转自点击打开链接 1.二维码的生成 将Zxing-core. ...

  8. OSWorkFlow流程配置文件具体解释

    AbstractWorkflow>> osworkflow中有关工作流流转的全部核心代码都在AbstractWorkflow中.BasicWorkflow就是派生自它,只是这个BasicW ...

  9. Windows server 2003 + IIS6 搭建Asp.net MVC执行环境

    安装.Net Framework4.0. 下载地址: http://www.microsoft.com/zh-cn/download/details.aspx?id=17718  安装WindowsS ...

  10. Spring3+ibatis (SQL Server)+pager-taglib.tld查询分页的实现

    pager-taglib分页開始~ 查了好多关于分页的技术,终于选定下面方法实现~ 1.首先下载jar包:pager-taglib.jar,pager-taglib.jar放在WEB-INF/lib文 ...