【UVA11806 Cheerleaders】 题解
题目链接:https://www.luogu.org/problemnew/show/UVA11806
容斥原理+组合数
正着找合♂fa的不好找,那就用总方案数-不合♂fa的
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1000;
const int mod = 1e6 + 7;
int T, k, m, n, ans, C[maxn][maxn];
void init()
{
C[0][0] = 1; C[1][0] = 1; C[1][1] = 1;
for(int i = 2; i <= 500; i++)
{
C[i][0] = 1;
for(int j = 1; j <= i; j++)
C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
}
}
int main()
{
init();
cin>>T;
for(int a = 1; a <= T; a++)
{
ans = 0;
cin>>n>>m>>k;
for(int i = 0; i < (1 << 4); i++)
{
int now_n = n, now_m = m, flag = 0;
if(i & (1 << 0)) now_n--, flag++;
if(i & (1 << 1)) now_n--, flag++;
if(i & (1 << 2)) now_m--, flag++;
if(i & (1 << 3)) now_m--, flag++;
if(flag % 2 == 1) ans = (ans - C[now_n*now_m][k] + mod)%mod;
else ans = (ans + C[now_n*now_m][k])%mod;
}
cout<<"Case "<<a<<": "<<ans%mod<<"\n";
}
}
【UVA11806 Cheerleaders】 题解的更多相关文章
- UVA-11806 Cheerleaders 计数问题 容斥定理
题目链接:https://cn.vjudge.net/problem/UVA-11806 题意 在一个mn的矩形网格里放k个石子,问有多少方法. 每个格子只能放一个石头,每个石头都要放,且第一行.最后 ...
- UVa11806 Cheerleaders(容斥原理)
11806 - Cheerleaders Time limit: 2.000 seconds C Cheerleaders In most professional sporting events, ...
- UVA11806 Cheerleaders
题意 PDF 分析 如果要求是某行某列没有石子很好算,就一个组合数. 然后要求某行某列有,就用容斥原理就行了. 时间复杂度\(O(k^2 + 16T)\) 代码 #include<iostrea ...
- 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. ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
随机推荐
- monodb分片集群部署
本文档基于MongoDB版本3.6.2 下载地址: 建议使用最新版本 https://www.mongodb.com/download-center#community 安装文件 集群ip及端口设计方 ...
- mysql-connector/python使用示例
1.下载安装connector/python 地址:https://dev.mysql.com/downloads/connector/python/ 下载的版本(mysql-connector-py ...
- hdu 1712 (分组背包)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17676 这个问题让我对分组背包更清晰了一点,主要是这个问题: 使用一维数组的 ...
- ASP.NET 后台验证 TextBox 值是否为数字
记得最开始 using System.Text.RegularExpressions; Regex m_regex = new System.Text.RegularExpressions.Regex ...
- 判断sql是否存在特定的对象
1 判断数据库是否存在if exists (select * from sys.databases where name = '数据库名') drop database [数据库名] 2 判断表是否存 ...
- require'模块化jquery和angular问题
require 模块化开发问题,正常自己写的模块 是exports 导出一个模块 //模块化引入jquery 不同和问题 require 引入jquery swiper .... 插件和库的时候需要 ...
- 大规模WEB服务技术
CPU负载的扩展很简单,增加相同结构的服务器,通过负载均衡来分散. I/O负载的扩展很困难.要考虑局部性.
- Codeforces Round #411 A. Fake NP
A. Fake NP time limit per test 1 second memory limit per test 256 megabytes Tavak and Seyyed a ...
- Python爬虫教程-28-Selenium 操纵 Chrome
我觉得本篇是很有意思的,闲着没事来看看! Python爬虫教程-28-Selenium 操纵 Chrome PhantomJS 幽灵浏览器,无界面浏览器,不渲染页面.Selenium + Phanto ...
- 如何有效防止API的重放攻击(转自阿里云)
API重放攻击(Replay Attacks)又称重播攻击.回放攻击,这种攻击会不断恶意或欺诈性地重复一个有效的API请求.攻击者利用网络监听或者其他方式盗取API请求,进行一定的处理后,再把它重新发 ...