【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 ...
随机推荐
- java web 开发入门
Java web,是java技术用来解决web互联网领域的技术总和.Java web技术主要包括客户端和服务端,java在客户端的服务有java applet,不过用的非常少,大部分应用在服务端,比如 ...
- flask_sqlalchemy filter 和filter_by的区别
1. filter需要通过类名.属性名的方式,类名.属性名==值.filter_by 直接使用属性名=值,可以看源码filter_by需要传一个 **kwargs 2. filter支持> &l ...
- HTML总结摘要
一 概述 1.什么是HTML? HyperText Markup Language,超文本标记语言,客户端技术的技术,负责页面展示. 2.HTML的特点 标签不区分大小写. 3.请求地址 HTML是客 ...
- Oracle中的索引详解(转载)
一. ROWID的概念 存储了row在数据文件中的具体位置:64位 编码的数据,A-Z, a-z, 0-9, +, 和 /, row在数据块中的存储方式 SELECT ROWID, last_name ...
- 【Python】安装配置Anaconda
优点:解决Python 库依赖问题 清华安装镜像 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
- char和varchar的区别
在建立数据库表结构的时候,为了给一个String类型的数据定义一个数据库的数据库类型,一般参考的都是char或者varchar,这两种选择有时候让人很纠结,今天想总结一下它们两者的区别,明确一下两者的 ...
- mac和windows自动清理内存工具
因为我比较懒,所以需要一款能自动清理电脑内存的工具,目的是设置内存最小值,然后自动清理. mac: drcleaner windows: MaxMem win10设置开机启动地址:C:\Program ...
- Suse LAMP setup
This page will describe the steps you have to take to install LAMP, which stands for Linux Apache Ma ...
- C#常用排序和查找算法
1.C#堆排序代码 private static void Adjust (int[] list, int i, int m) { int Temp = list[i]; int j = i * 2 ...
- [问题记录]cocos的lua绑定安装pyyaml报错
描述:按照readme中的文档操作报错,提示python2.7没有安装,但是确实已经安装了,而且也设置环境变量成功了. 解决: 在D盘新建register.py的文件,内容如下: # # script ...