UVA11806 Cheerleaders
题意
分析
如果要求是某行某列没有石子很好算,就一个组合数。
然后要求某行某列有,就用容斥原理就行了。
时间复杂度\(O(k^2 + 16T)\)
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
rg T data=0;
rg int w=1;
rg char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
{
data=data*10+ch-'0';
ch=getchar();
}
return data*w;
}
template<class T>T read(T&x)
{
return x=read<T>();
}
using namespace std;
typedef long long ll;
co int K=500,mod=1e6+7;
int C[K+10][K+10];
int add(int x,int y)
{
x+=y;
return x>=mod?x-mod:x;
}
int sub(int x,int y)
{
x-=y;
return x<0?x+mod:x;
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
C[0][0]=1;
for(int i=0;i<=K;++i)
{
C[i][0]=C[i][i]=1;
for(int j=1;j<i;++j)
C[i][j]=add(C[i-1][j],C[i-1][j-1]);
}
int T=read<int>();
for(int kase=1;kase<=T;++kase)
{
int n,m,k,sum=0;
read(n);read(m);read(k);
for(int s=0;s<16;++s)
{
int b=0,r=n,c=m;
if(s&1)
r--,b++;
if(s&2)
r--,b++;
if(s&4)
c--,b++;
if(s&8)
c--,b++;
if(b&1)
sum=sub(sum,C[r*c][k]);
else
sum=add(sum,C[r*c][k]);
}
printf("Case %d: %d\n",kase,sum);
}
return 0;
}
UVA11806 Cheerleaders的更多相关文章
- 【UVA11806 Cheerleaders】 题解
题目链接:https://www.luogu.org/problemnew/show/UVA11806 容斥原理+组合数 正着找合♂fa的不好找,那就用总方案数-不合♂fa的 #include < ...
- 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 (容斥)
题目链接 Solution 可以考虑到总方案即为 \(C_{nm}^k\) . 考虑到要求的是边缘都必须至少有 \(1\) ,所以考虑不合法的. 第一行和最后一行没有的方案即为 \(C_{(n-1)m ...
- uva 11806 Cheerleaders
// uva 11806 Cheerleaders // // 题目大意: // // 给你n * m的矩形格子,要求放k个相同的石子,使得矩形的第一行 // 第一列,最后一行,最后一列都必须有石子. ...
- UVA 11806 Cheerleaders dp+容斥
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
- UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)
UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举) 题意分析 给出n*m的矩形格子,给出k个点,每个格子里面可以放一个点.现在要求格子的最外围一圈的每行每列,至少要放一个 ...
- 【递推】【组合数】【容斥原理】UVA - 11806 - Cheerleaders
http://www.cnblogs.com/khbcsu/p/4245943.html 本题如果直接枚举的话难度很大并且会无从下手.那么我们是否可以采取逆向思考的方法来解决问题呢?我们可以用总的情况 ...
- Cheerleaders UVA - 11806 计数问题
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
随机推荐
- python脚本9_打印斐波那契数列
#打印斐波那契数列 f0 = 0 f1 = 1 for n in range(2,101): fn = f1 + f0 if fn <= 100: print(fn) f0 = f1 f1 = ...
- Neutron三层网络服务实现原理
Neutron 对虚拟三层网络的实现是通过其 L3 Agent (neutron-l3-agent).该 Agent 利用 Linux IP 栈.route 和 iptables 来实现内网内不同网络 ...
- 杀死dialog
先 pkill -9 normal.sh 和 pkill -9 terminal_ui.sh 然后在pkill -9 dialog
- hdu 6114 chess(排列组合)
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- String类运算符重载,自己实现
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- 前端url传递编码问题
JAVASCRIPT中URL 传递参数(特殊字符)解决方法及转码解码的介绍 有些符号在URL中是不能直接传递的,如果要在URL中传递这些特殊符号,那么就要使用他们的编码了.下表中列出了一些URL特殊符 ...
- 什么是web?什么是web服务器?什么是应用服务器?
1.什么是Web? 简单来说,Web就是在Http协议基础之上,利用浏览器进行访问的网站.目前来看最常用的意义是指在 Intenet 上和 HTML 相关的部分.换句话说,目前在 Intenet 上通 ...
- 2018.11.13 N4010A 通信设置
设置电脑之IP地址及Subnet mask. IP address: 192.168.1.2 Subnet mask: 255.255.255.0, 其它选项为默认. 然后点击OK ...
- about system (pause) in cpp
Which is best way to pause the console in C++ programs? using cin.get() or using system("pause& ...
- 【PL/SQL编程】变量和常量
1. 变量格式 <变量名><数据类型>[(长度):=<初始值>]; v_countryname varchar2(50):='中国'; 2. 常量格式 <常量 ...