【题目链接】:http://codeforces.com/problemset/problem/768/F

【题意】



让你把f个food和w个wine装在若干个栈里面;

每个栈只能装food或者是wine;

且装wine和food的栈交替出现;

然后是随机等可能地分配方案;

问你wine的栈里面,wine的数量都大于h的概率是多少;

【题解】



可以把一个栈里面的东西看成是线性的;

即如果某个栈里面有3个food;

就相当于3个food排成了一排;

这样,原问题等价于;

有f个food放在直线上;

然后有f+1个位置可以放wine;

这f+1个位置中,每个位置放置的wine的数量都必须多于h个;

则先从这f+1个位置中选出i个位置

C(f+1,i)

然后先把这i个位置都放h个wine;

则剩余rest=w-h*i个wine;

然后相当于解一个方程

x1+x2+…+xi=rest且x1,x2..xi都是正整数;

求它的不同解个数;

高中数学题。隔板法;

答案就为

C(rest−1,i−1)

枚举i的时候答案递增

C(f+1,i)∗C(w−h∗i−1,i−1)

这样就能把分子算出来了;

而分母是

C(f+w,w)

即随便选w个位置放wine,其他地方放food就是了;

写个乘法逆元;

然后注意边界,即w=0的时候,这时候是没有wine的了;

所以不存在说wine会小于等于h的情况,即任何方案都可行;

有个f+w,所以阶乘得算到2*1e5….



【Number Of WA】



4



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e5+100;
const LL MOD = 1e9+7; LL fac[N+100],rfac[N+100];
LL f,w,h; LL ksm(LL x,LL y)
{
LL t = 1;
while (y)
{
if (y&1) t = (t*x)%MOD;
x = (x*x)%MOD;
y>>=1;
}
return t;
} void pre()
{
fac[0] = 1;
rep1(i,1,N) fac[i] = (fac[i-1]*i)%MOD;
rfac[N] = ksm(fac[N],MOD-2);
rep2(i,N,1) rfac[i-1] = (rfac[i]*i)%MOD;
} LL C(LL n,LL m)
{
//n!/(n-m!)*m!
return (fac[n]*rfac[n-m]%MOD)*rfac[m]%MOD;
} int main()
{
//Open();
Close();//scanf,puts,printf not use
//init??????
pre();
cin >> f >> w >> h;
LL fz = 0;
for (LL i = 1;i <= f+1;i++)
{
if ((h+1)*i>w) break;
fz = fz+C(f+1,i)*C(w-h*i-1,i-1)%MOD;
fz%=MOD;
}
LL fm = C(f+w,w);
if (w==0) fz = fm;
LL ans = fz*ksm(fm,MOD-2)%MOD;
cout << ans << endl;
return 0;
}

【codeforces 768F】Barrels and boxes的更多相关文章

  1. 【codeforces 768F】 Barrels and boxes

    http://codeforces.com/problemset/problem/768/F (题目链接) 题意 A,B两种物品可以装到栈中,每个栈只能存放一种物品,容量没有限制.现在讲所有栈排成一列 ...

  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. spring data JPA使用quartz定时器的具体实现

    第一步.在pom.xml中的配置 <!--quartz--> <dependency> <groupId>org.quartz-scheduler</grou ...

  2. NetOps Defined

    https://www.logzilla.net/2017/06/20/the-network-operations-top-5.html

  3. html 页面刷新

    JS 脚本 方法1 setInterval 函数 定时局部刷新用到jQuery里面的setInterval方法, 该函数每隔一段时间请求一次数据,然后将请求结果返回给前端HTML实现刷新. setIn ...

  4. pthread_cond 唤醒特定线程的方法

  5. HDU 4344

    其实不过是大整数分解... 注意两点:注意L 不能==N 但是,N却可以是素数...囧 #include <iostream> #include <cstdio> #inclu ...

  6. 面试宝典之基本的C#面试问答

    下文是100个基本的C#面试问答清单.这些面试问题简单.直接了当,涵盖了C#最基本的概念,大部分和面向对象的概念相关.所以如果你在准备C#面试,我建议你必须掌握这100个基本的C#面试问答来复习你的C ...

  7. 解决 Mac OS X 10.11 安装 sip 没有权限的问题

    在搭建 PYQT 的过程中我遇上了一个非常恶心的问题,在安装 sip 的时候编译源代码之后的安装过程中一直提示我:Operation not permitted ,我甚至重装了系统也无济于事,终于通过 ...

  8. [HTML5] Accessibility Implementation for complex component

    When you developing a complex component by your own, one thing you cannot ignore is Accessibility. C ...

  9. 【ruby项目,语言提交检查(一)】怎样高速学习ruby ?

    怎样高速学习ruby ? 学习语言最快的思路. 变量,常量,变量类型,操作符. 逻辑语句如 if, else, switch, for, foreach, do while, break, 等等.要学 ...

  10. sqlite学习笔记6:更新表数据-update

    一 条件推断 在SQL中条件推断使用where,相当于其它变成语言中的if,基本使用方法如: SELECT column1, column2, columnN FROM table_name WHER ...