uva 11806 Cheerleaders (容斥)
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 (容斥)的更多相关文章
- Cheerleaders UVA - 11806(容斥+二进制技巧)
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...
- UVA 11806 组合数学+容斥
UVA: https://vjudge.net/problem/UVA-11806 AC代码 #include <bits/stdc++.h> #define pb push_back # ...
- UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)
UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举) 题意分析 给出n*m的矩形格子,给出k个点,每个格子里面可以放一个点.现在要求格子的最外围一圈的每行每列,至少要放一个 ...
- uva 11806 Cheerleaders
// uva 11806 Cheerleaders // // 题目大意: // // 给你n * m的矩形格子,要求放k个相同的石子,使得矩形的第一行 // 第一列,最后一行,最后一列都必须有石子. ...
- uva - The Lottery(容斥,好题)
10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...
- UVA11806 Cheerleaders (容斥)
题目链接 Solution 可以考虑到总方案即为 \(C_{nm}^k\) . 考虑到要求的是边缘都必须至少有 \(1\) ,所以考虑不合法的. 第一行和最后一行没有的方案即为 \(C_{(n-1)m ...
- 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 (组合+容斥原理)
自己写的代码: #include <iostream> #include <stdio.h> #include <string.h> /* 题意:相当于在一个m*n ...
随机推荐
- codevs1214 线段覆盖
1214 线段覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定x轴上的N(0<N<100)条线段, ...
- 开始使用Apache弗林克和Mapr Streams
Introduction MapR Ecosystem Package 2.0 (MEP) is coming with some new features related to MapR Strea ...
- LUOGU 3089 后缀排序(模板)
传送门 解题思路 这是一个神奇的算法,sa[i]表示排名第i为的元素是啥,rk[i]表示第i个元素排名是啥.然后使用基数排序+倍增的思想去处理.主要是参考的这位大佬的博客(https://www.cn ...
- leetcode 21-30 easy
21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list s ...
- listView中的button控件获取索引
1.在listitem中初始化button的时候,给该button添加一个setTag方法,将此时的索引值传进去,然后在button的onclick事件中调用view的getTag方法,即可将list ...
- 【JZOJ5060】【GDOI2017第二轮模拟day1】公路建设 线段树+最小生成树
题面 在Byteland一共有n 个城市,编号依次为1 到n,它们之间计划修建m条双向道路,其中修建第i 条道路的费用为ci. Byteasar作为Byteland 公路建设项目的总工程师,他决定选定 ...
- Python2.7用sys.stdout.write实现打印刷新
如何能在控制台实现在一行中显示进度的信息呢,就像使用pip安装时的进度那样. 如果用print则会打印成多行,下面这个小技巧可以在一行中打印: import time import sys if __ ...
- B站直播 DEMO ijkplayerDemo
http://blog.csdn.net/kengsir/article/details/51750879 一. 下载ijkplayer ijkplayer下载地址 下载完成后解压, 解压后文件夹内部 ...
- 【风马一族_php】数组函数
原文来自:http://www.cnblogs.com/sows/p/6045699.html (博客园的)风马一族 侵犯版本,后果自负 2016-11-09 15:56:26 数组 函数 php- ...
- JavaScript--结合CSS变形、缩放能拖拽的登录框
上例图: 代码块: <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...