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

  容斥原理,从反面去想。统计边界上都没有石子的情况。这时候就要用到容斥原理了。

代码如下:

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; typedef long long LL;
const LL MOD = ;
const int N = ;
const int M = N * N;
LL C[M][M]; void PRE() {
C[][] = ;
for (int i = ; i < M; i++) {
C[i][] = ;
for (int j = ; j <= i; j++) {
C[i][j] = (C[i - ][j - ] + C[i - ][j]) % MOD;
}
}
} int main() {
int n, m, k, T, cas = ;
PRE();
cin >> T;
for (int cas = ; cas <= T; cas++) {
cin >> n >> m >> k;
LL ans = ;
for (int i = ; i < ; i++) {
int r = n, c = m, odd = false;
if (i & ) r--, odd = !odd;
if (i & ) r--, odd = !odd;
if (i & ) c--, odd = !odd;
if (i & ) c--, odd = !odd;
if (r < || c < ) ;
else if (odd) ans -= C[r * c][k];
else ans += C[r * c][k];
while (ans < ) ans += MOD;
while (ans >= MOD) ans -= MOD;
}
printf("Case %d: ", cas);
cout << ans << endl;
}
return ;
}

——written by Lyon

uva 11806 Cheerleaders (容斥)的更多相关文章

  1. Cheerleaders UVA - 11806(容斥+二进制技巧)

    #include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...

  2. UVA 11806 组合数学+容斥

    UVA: https://vjudge.net/problem/UVA-11806 AC代码 #include <bits/stdc++.h> #define pb push_back # ...

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

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

  4. uva 11806 Cheerleaders

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

  5. uva - The Lottery(容斥,好题)

    10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...

  6. UVA11806 Cheerleaders (容斥)

    题目链接 Solution 可以考虑到总方案即为 \(C_{nm}^k\) . 考虑到要求的是边缘都必须至少有 \(1\) ,所以考虑不合法的. 第一行和最后一行没有的方案即为 \(C_{(n-1)m ...

  7. UVA 11806 Cheerleaders dp+容斥

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

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

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

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

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

随机推荐

  1. java实体类的属性名首字母不能大写,不然el表达式无法取值

    摘要:Java命名规范中,实体类属性名以小写字母开头,但并没有说不能以大写字母开头,然而事实告诉我,大写真不行 https://www.cnblogs.com/jnhs/p/10025757.html

  2. bzoj3064/洛谷P4314 CPU监控【线段树】

    好,长草博客被催更了[?] 我感觉这题完全可以当作线段树3 线段树2考加法和乘法标记的下放顺序,这道题更丧心病狂[?] 很多人可能跟我一样,刚看到这道题秒出思路:打一个当前最大值一个历史最大值不就完事 ...

  3. 解决WSL上运行plantUML中文乱码问题

    生成UML图命令: java -jar plantuml.jar -charset UTF-8 my.txt 1. 保证my.txt 使用uft-8编码 2. wsl中安装中文字体: 如: sudo ...

  4. Django 的逆向解析url(转)

    Django中提供了一个关于URL的映射的解决方案,你可以做两个方向的使用: 1.有客户端的浏览器发起一个url请求,Django根据URL解析,把url中的参数捕获,调用相应的试图, 获取相应的数据 ...

  5. FJWC2018

    晚上水到8:40,感觉药丸. 把电脑带回寝室,大半夜敲键盘…… bzoj5254红绿灯 泰迪每天都要通过一条路从家到学校,这条路的起点是泰迪家,终点则是学校. 这条路中间还有n个路口,从第i-1个路口 ...

  6. 跨域知识(二)——JSONP

    JSONP是服务器与客户端跨源通信的常用方法.最大特点就是简单适用,老式浏览器全部支持,服务器改造非常小. 它的基本思想是,网页通过添加一个<script>元素,向服务器请求JSON数据, ...

  7. 怎样做一个iOS App的启动分层引导动画?

    一. 为什么要写这篇文章? 这是一个很古老的话题,从两年前新浪微博开始使用多层动画制作iOS App的启动引导页让人眼前一亮(当然,微博是不是历史第一个这个问题值得商榷)之后,各种类型的引导页层出不穷 ...

  8. PLAY2.6-SCALA(三) 数据的返回与保存

    1.修改默认的Content-Type 自动设置内容类型为text/plain val textResult = Ok("Hello World!") 自动设置内容类型为appli ...

  9. Python sorted

    sorted函数: iterable:是可迭代类型;cmp:用于比较的函数,比较什么由key决定,有默认值,迭代集合中的一项;key:用列表元素的某个属性和函数进行作为关键字,有默认值,迭代集合中的一 ...

  10. homestead 重复出错

    vboxmanage list vms "homestead-7" {2c8b0ea2-d862-4f4e-bcb2-2d7db848686f} vboxmanage unregi ...