【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 [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- Windows 10 中 VMware 要求禁用 Device Guard 问题
今天在打开虚拟机的时候,突然出现下面这个错误.网上给了很多教程,基本上都是禁用 Device Guard 和关闭 Hyper-v,博主按照其方法操作,依旧出现下面错误.后来经过不懈努力,终于找到解决办 ...
- curator 分布式锁InterProcessMutex
写这篇文章的目的主要是为了记录下自己在zookeeper 锁上踩过的坑,以及踩坑之后自己的一点认识; 从zk分布式锁原理说起,原理很简单,大家也应该都知道,简单的说就是zookeeper实现分布式锁是 ...
- C_数据结构_栈
# include <stdio.h> # include <malloc.h> # include <stdlib.h> typedef struct Node ...
- 《Linux内核分析》第八周学习总结
<Linux内核分析>第八周学习总结 ——进程的切换和系统的一般执行过程 姓名:王玮怡 学号:20135116 ...
- Jquery画折线图、柱状图、饼图
1.今天做了一个折线图,首先需要导js文件.这里有一个demo:http://files.cnblogs.com/files/feifeishi/jquery_zhexiantubingtuzhuzh ...
- 06-java学习-方法的学习
方法定义 方法类型 方法涉及的知识: 修饰符.返回类型,命名规则,参数列表 方法常见错误 方法概念的深入理解 为什么会有方法? 方法帮助解决哪些问题? 方法可以简化复杂问题的解决
- 『编程题全队』Beta 阶段冲刺博客四
1.提供当天站立式会议照片一张 2.每个人的工作 (有work item 的ID) (1) 昨天已完成的工作 孙志威: 1.新增添加提醒事项的按钮 2.添加了新建提醒框 3.测试了新的SubTask思 ...
- Exception while invoking TaskListener: Exception while invoking TaskListener: null
https://community.alfresco.com/thread/225041-exception-while-invoking-tasklistener-null Ok, so the p ...
- activiti engine.schema.update DB_SCHEMA_UPDATE_FALSE
engine.properties # engine propertiesengine.schema.update=trueengine.activate.jobexecutor=falseengin ...
- python学习笔记六——堆栈和队列
4.2.3 列表的查找.排序.反转 list列表可以进行添加.删除操作,此外List列表还提供了查找元素的方法.list列表的查找提供了两种方式,一种是使用index方法返回元素在列表中的位置,另一种 ...