【codeforces 768F】 Barrels and boxes
http://codeforces.com/problemset/problem/768/F (题目链接)
题意
A,B两种物品可以装到栈中,每个栈只能存放一种物品,容量没有限制。现在讲所有栈排成一列,AB相间,问存B的栈长大于H的概率。
Solution
震惊!F竟是个大水题。。。枚举长度隔板法搞一搞就好了。。
细节
注意判0分成0组的情况?LL
代码
// codeforces768F
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define inf 2147483640
#define MOD 1000000007
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; const int maxn=100010;
LL fac[maxn],ifac[maxn];
int F,W,H,n;
LL P,Q; LL C(LL n,LL m) {
if (n==m && n==-1) return 1;
return n<0||m<0||n<m ? 0 : fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;
}
LL power(LL a,LL b) {
LL res=1;
while (b) {
if (b&1) (res*=a)%=MOD;
b>>=1;(a*=a)%=MOD;
}
return res;
}
int main() {
scanf("%d%d%d",&F,&W,&H);
n=F+W;
fac[0]=1;for (int i=1;i<=100000;i++) fac[i]=fac[i-1]*i%MOD;
ifac[100000]=power(fac[100000],MOD-2);
for (int i=100000;i;i--) ifac[i-1]=ifac[i]*i%MOD;
for (int i=1;i<=n;i++) {
int w=(i&1) ? 1 : 2;
for (int j=i>>1;j<=(i+1)>>1;j++) {
LL q=C(F-1,j-1)*C(W-1,i-j-1)%MOD*w%MOD;
LL p=C(F-1,j-1)*C(W-1LL*(i-j)*H-1,i-j-1)%MOD*w%MOD;
(Q+=q)%=MOD,(P+=p)%=MOD;
}
}
printf("%lld",P*power(Q,MOD-2)%MOD);
return 0;
}
【codeforces 768F】 Barrels and boxes的更多相关文章
- 【codeforces 768F】Barrels and boxes
[题目链接]:http://codeforces.com/problemset/problem/768/F [题意] 让你把f个food和w个wine装在若干个栈里面; 每个栈只能装food或者是wi ...
- 【24.67%】【codeforces 551C】 GukiZ hates Boxes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【31.72%】【codeforces 604B】More Cowbell
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- 使用Hexo+Github搭建属于自己的博客(基础)
前言 hexo是一个台湾人做的基于Node.js的静态博客程序,优势是生成静态文件的速度非常快,支持markdown, 我最终选定它的原因是它速度快而且不容易出错,并且可以一键部署到github或者其 ...
- C#实现.Net对邮件进行DKIM签名和验证,支持附件,发送邮件签名后直接投递到对方服务器(无需己方邮件服务器)
项目地址 https://github.com/xiangyuecn/DKIM-Smtp-csharp 主要支持 对邮件进行DKIM签名,支持带附件 对整个邮件内容(.eml文件)的DKIM签名进行验 ...
- Http指南(1)
网关:是一种特殊的服务器,作为其他服务器的中间实体使用; Agent代理:所有发布web请求的应用程序都是HTTP Agent代理.Web浏览器其实就是一种代理; HTTP报文是在HTTP应用程序之间 ...
- Centos7下关于系统用户密码规则-运维笔记
针对Centos7下的系统用户的密码规则复杂度的设置,处于安全考虑,说明如下: 一.设置密码规则 1)密码长度.有效期 /etc/login.defs文件是当创建用户时的一些规划,比如创建用户时,是否 ...
- 磁盘挂载问题:Fdisk最大只能创建2T分区的盘,超过2T使用parted
需求说明:云服务器上买了一块8T的磁盘,准备挂载到服务器上的/data目录下. ===================================parted命令说明=============== ...
- The Contest CodeForces - 813A (思维)
Pasha is participating in a contest on one well-known website. This time he wants to win the contest ...
- SVN入门教程
1. 什么是SVN SVN全名Subversion,即版本控制系统.SVN与CVS一样,是一个跨平台的软件,支持大多数常见的操作系统. 作为一个开源的版本控制系统,Subversion管理者随时间改变 ...
- Java基础知识中的注意事项
设置Java的相关路径,举例: JAVA_HOME --> C:\Program Files\Java\jdk1.8.0_191 Path ---> C:\Program Fil ...
- Windows 安装 docker 以及1709的简单使用
PS C:\> Install-Module -Name DockerMsftProvider -Repository PSGallery -Force PS C:\> Install-P ...
- Bootstrap @Media分类
手机的屏幕比较小,宽度通常在600像素以下:PC的屏幕宽度,一般都在1000像素以上(目前主流宽度是1366×768)设置相应的min-width和max-width值 所以响应式设计一般对600 ...