【题目链接】: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. 【CodeForces 574B】Bear and Three Musketeers

    [链接] 我是链接,点我呀:) [题意] [题解] 枚举每一条边(x,y) 然后再枚举y的出度z 看看g[x][z]是否等于1(表示联通) 如果等于1就说明找到了一个三元环,则尝试用它们的出度和-6更 ...

  2. poj 2139 flord水题

    读懂题意就简单了 #include<stdio.h> #define inf 999999999 #define N 310 int f[N]; int map[N][N]; int ma ...

  3. asp.net mvc--传值-前台->后台

    前端传值->后端 一.Model Binding 方式 前台 @model ADMgr.Web.Models.ListModel 后台 [HttpPost] public ActionResul ...

  4. nodejs-配置vs code的插件

    在windows上安装好npm后,再在终端里使用npm安装express,再安装express-generator  进入express的目录, 在终端中执行 npm install 启动expres ...

  5. [笔记][Java7并发编程实战手冊]系列文件夹

    推荐学习多线程之前要看的书. [笔记][思维导图]读深入理解JAVA内存模型整理的思维导图文章里面的思维导图或则相应的书籍.去看一遍. 能理解为什么并发编程就会出现故障. Java7并发编程实战手冊 ...

  6. [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 ...

  7. 9patch生成图片

    private Bitmap get_ninepatch(int id,int x, int y, Context context){ // id is a resource id for a val ...

  8. UpdateParameterUtils

    /**  *   */ package com.neptune.business.api.job; import java.text.SimpleDateFormat; import java.uti ...

  9. unity3d Pathfinding插件使用

    Overview The central script of the A* Pathfinding Project is the script 'astarpath.cs', it acts as a ...

  10. kentico中的page template的使用

    父页面使用自己的template 子页面,也使用自己的template. 然后父页面中需要添加一个place holder. 子页面的继承,选择inherit only master page. 这样 ...