【codeforces 768F】Barrels and boxes
【题目链接】: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的更多相关文章
- 【codeforces 768F】 Barrels and boxes
http://codeforces.com/problemset/problem/768/F (题目链接) 题意 A,B两种物品可以装到栈中,每个栈只能存放一种物品,容量没有限制.现在讲所有栈排成一列 ...
- 【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 [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- windowbuilder01 按钮事件监听
- mybatis逆向工程不生成Example
mybatis逆向生成映射文件时会生成一大堆example文件,没感觉有啥用,可以手动删除这些多余的东西,使项目变得好看许多 也可以通过配置达到目的: 原配置: <table tableName ...
- BA-siemens-TX-IO模块照片
西门子楼宇自控用到的P1模块是这样的 TX-16D模块是这样的 TX-8X模块是这样的: TX-6R模块是这样的: TX-IO总线连接模块( 此模块供电和通讯加起来共需三芯线):
- [Angular] ngx-formly (AKA angular-formly for Angular latest version)
In our dynamic forms lessons we obviously didn’t account for all the various edge cases you might co ...
- 图像算法研究---Adaboost算法具体解释
本篇文章先介绍了提升放法和AdaBoost算法.已经了解的可以直接跳过.后面给出了AdaBoost算法的两个样例.附有详细计算过程. 1.提升方法(来源于统计学习方法) 提升方法是一种经常使用的统计学 ...
- linux 下password加密程序(能够用于替换shadow文件里的用户password)
源代码例如以下: #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]){ if(arg ...
- 12. mysql show status
状态名 作用域 详解 Aborted_clients Global 因为client没有正确关闭连接导致client终止而中断的连接数 Aborted_connects Global 试图连接到MyS ...
- iOS:编译错误[__NSDictionaryM objectAtIndexedSubscript:]: unrecognized selector sent to instance 0xa79e61
这个意思是,__NSDictionaryM 无法将值传到下标索引对象,言简意赅就是数组越界.可是再看看,这是数组吗?不是,所以.遇到这样的crash,我这里有两种情况: 1.首先看看你 indexP ...
- POJ 2796 / UVA 1619 Feel Good 扫描法
Feel Good Description Bill is developing a new mathematical theory for human emotions. His recent ...
- 广东工业大学2016校赛决赛-网络赛 1169 Problem A: Krito的讨伐 优先队列
Problem A: Krito的讨伐 Description Krito终于干掉了99层的boss,来到了第100层.第100层可以表示成一颗树,这棵树有n个节点(编号从0到n-1),树上每一个节点 ...