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的更多相关文章

  1. 【codeforces 768F】Barrels and boxes

    [题目链接]:http://codeforces.com/problemset/problem/768/F [题意] 让你把f个food和w个wine装在若干个栈里面; 每个栈只能装food或者是wi ...

  2. 【24.67%】【codeforces 551C】 GukiZ hates Boxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【31.72%】【codeforces 604B】More Cowbell

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. [Codeforces1137D]Cooperative Game

    [Codeforces1137D]Cooperative Game Tags:题解 题意 这是一道交互题. 给你一张下面这样的地图,由一条长为\(t\)的有向链和一个长为\(c\)的环构成. 现在你有 ...

  2. openhtmltopdf 支持自定义字体、粗体

    一.支持自定义字体 private static void renderPDF(String html, OutputStream outputStream) throws Exception { t ...

  3. [JSOI2016]轻重路径[树链剖分]

    题意 题目链接 分析 先对原树树剖,在一次删点操作后从根节点开始二分,如果一条边从重边变成轻边,必然有 \(size_u\le \frac{1}{2}size_{rt}\) (取等号是特判对应儿子消失 ...

  4. SpringBoot日记——任务处理 之 异步、定时、邮件

    ---恢复内容开始--- 直接步入正题. 异步任务 异步任务比较简单,只需要两个注解就可以搞定,我们直接来看如何使用: 1.创建一个service,带上@EnableAsync,就是开启异步任务的注解 ...

  5. Linux下分布式系统以及CAP理论分析

    CAP理论被很多人拿来作为分布式系统设计的金律,然而感觉大家对CAP这三个属性的认识却存在不少误区,那么什么是CAP理论呢?CAP原本是一个猜想,2000年PODC大会的时候大牛Brewer提出的,他 ...

  6. 先埋锅-CF-Valid BFS?-差一点没交上

    #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...

  7. slf4j的java包冲突问题

  8. Java 模仿 C# 字典 一例

    List<Map.Entry<Integer, String>> orderStatusList = new ArrayList<Map.Entry<Integer ...

  9. Kali2.0的简单使用--开启root用户登录

    1. 安装完kali之后 2. 修改/etc/ssh/sshd_conf的文件 将: #PasswordAuthentication no 修改为: PasswordAuthentication ye ...

  10. $().click()和$(document).on('click','要选择的元素',function(){})的不同

    1. $(选择器).click(fn) 当选中的选择器被点击时触发回调函数fn.只针对与页面已存在的选择器; 2.$(document).on('click','要选择的元素',function(){ ...