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. 以英雄联盟的方式建模,谈对依赖注入(DI)的理解以及Autofac的用法(一)

    一.前言 近期在探索分层架构和架构设计,选择了领域驱动作为5年.Net开发后的新的方向,不可避免的接触了IoC/DI方面的技术.目前通过反射或其他方法都已实现,但只知其一,并没有考虑为什么要这么做,同 ...

  2. Git push 时如何避免出现 "Merge branch 'master' of ..."

    在使用 Git 的进行代码版本控制的时候,往往会发现在 log 中出现 "Merge branch 'master' of ..." 这句话,如下图所示.日志中记录的一般为开发过程 ...

  3. Jvm 10 升级笔记

    移除了 JPEGCodec https://www.cnblogs.com/liaolongjun/p/6878359.html

  4. 《Linux内核分析》第四周学习总结

    <Linux内核分析>第四周学习总结                         ——扒开系统调用的三层皮 姓名:王玮怡  学号:20135116 理论总结部分: 第一节 用户态.内核 ...

  5. UserControl 的一个值得注意的问题 [属性" * "的代码生成失败.错误是:"程序集"*.Version=1.0.0.0,Culture=neutral,..........无标记为序列化"

    开发时在做UserControl,需要注意的List<>集合问题~~~! 其他类型的集合可能也存在这样的问题,但是我没去测试,在写集合的时候一般List<>用的多点,所以经常碰 ...

  6. jdbcTemplete(转)

    文章来源:http://blog.csdn.net/dyllove98/article/details/7772463 JdbcTemplate主要提供以下五类方法: execute方法:可以用于执行 ...

  7. R和python语言如何求平均值,中位数和众数

    均值是通过取数值的总和并除以数据序列中的值的数量来计算. R语言平均值公式: mean(x, trim = 0, na.rm = FALSE, ...)#x - 是输入向量.trim - 用于从排序的 ...

  8. docker:Dockerfile构建LNMP平台

    docker:Dockerfile构建LNMP平台   1.dockerfile介绍  Dockerfile是Docker用来构建镜像的文本文件,包含自定义的指令和格式.可以通过docker buil ...

  9. 转帖: Serverless架构模式简介

    Serverless架构模式简介   原贴地址:https://blog.csdn.net/chdhust/article/details/71250099?utm_medium=referral&a ...

  10. [转自知乎]飞腾国产CPU的部分知识

    1. 作者:常成链接:https://www.zhihu.com/question/48948852/answer/113595308来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...