【题目链接】: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. ORA-29857: 表空间中存在域索引和/或次级对象

    今天小编在操作 oracle 数据库,删除表空间时引发了异常!! SQL> drop tablespace nbmap including contents; 为什么会造成以上的异常呢? 根据小 ...

  2. POJ 2157 How many ways??

    How many ways?? Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origina ...

  3. POJ 2019

    简单的RMQ,可我怎么写都WA.不明白,找了一个和我相似的贴过了,要赶着去外婆家. #include <iostream> #include <algorithm> #incl ...

  4. 【C/C++多线程编程之十】pthread线程私有数据

    多线程编程之线程私有数据      Pthread是 POSIX threads 的简称.是POSIX的线程标准.         线程同步从相互排斥量[C/C++多线程编程之六]pthread相互排 ...

  5. [HTML5] How Visible vs. Hidden Elements Affect Keyboard/Screen Reader Users (ARIA)

    There are many techniques for hiding content in user interfaces, and not all are created equal! Lear ...

  6. exFAT格式

    买了一个64GB的T卡,发如今Windows XP上格式化."文件系统"仅仅有exFAT选项. 用这个exFAT格式化还失败了. 给XP打上KB955704补丁,能够用exFAT格 ...

  7. 韩国IT业是怎么走向国际我们须要学习什么

    无论从国土面积仍是从人口数量上来衡量.韩国都不能算是一个大国,而且自然资本十分缺乏,即是在这种情况下,韩国经过几十年的尽力开展变成技能大国,格外是在IT这种新经济范畴更是引人注目.并诞生了三星等国际级 ...

  8. NFS安装和配置

    ---------------------------------------------------------------------------------------------------- ...

  9. Windows 8.1内置微软五笔输入法

    微软五笔输入法採用86版编码,不是Windows 8.1系统的中文语言的缺省输入法,你在使用它之前须要把它加入到系统输入法中. 在控制面板双击"",然后加入微软五笔输入法. wat ...

  10. [C++设计模式] iterator 迭代器模式

    迭代器模式定义:提供一种方法顺序訪问一个聚合对象中各个元素,而又不须要暴露该对象. 迭代器分内部迭代器和外部迭代器.内部迭代器与对象耦合紧密,不推荐使用. 外部迭代器与聚合容器的内部对象松耦合,推荐使 ...