【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 [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- 洛谷—— P1220 关路灯
https://www.luogu.org/problem/show?pid=1220 题目描述 某一村庄在一条路线上安装了n盏路灯,每盏灯的功率有大有小(即同一段时间内消耗的电量有多有少).老张就住 ...
- POJ 2470 Ambiguous permutations(简单题 理解题意)
[题目简述]:事实上就是依据题目描写叙述:A permutation of the integers 1 to n is an ordering of these integers. So the n ...
- Geeks - Range Minimum Query RMQ范围最小值查询
使用线段树预处理.能够使得查询RMQ时间效率在O(lgn). 线段树是记录某范围内的最小值. 标准的线段树应用. Geeks上仅仅有两道线段树的题目了.并且没有讲到pushUp和pushDown操作. ...
- Java-MyBatis:MyBatis 3 入门
ylbtech-Java-MyBatis:MyBatis 3 入门 1.返回顶部 1. 入门 安装 要使用 MyBatis, 只需将 mybatis-x.x.x.jar 文件置于 classpath ...
- MyEclipse安装TestNG
1.获取TestNG运行包. (1).直接下载*.jar包并导入项目中. (2).maven下载. http://testng.org/doc/download.html 2.为IDE加载TestNG ...
- 了解和解决SQL SERVER阻塞问题(copy)
http://support.microsoft.com/kb/224453 Summary In this article, the term "connection" refe ...
- 复杂一些的SQL语句
表连接查询得到结果集后添加数据 INSERT INTO #saleSplitProduct(saleorderID,ProductCode,ProductNum,ProductPrice, produ ...
- Markdown标记语言
Markdown 是一种轻量级标记语言,创始人为约翰·格鲁伯(John Gruber).它允许人们“使用易读易写的纯文本格式编写文档,然后转换成有效的XHTML(或者HTML)文档”.这种语言吸收了很 ...
- 『转』Writing Well
这是前辈Julie Zhuo的最新关于写作的文章,昨天写下-进行总结和阅读思考 这是一篇关于提笔写作的文章,首发在The looking glass...前辈每周都会回答一个读者的问题耶--This ...
- protocol 和delegate(协议和代理)的区别
定义 protocol:中文叫协议,一个只有方法体(没有具体实现)的类,Java中称作接口,实现协议的类必须实现协议中@required标记的方法(如果有的话): delegate:中文叫代理或委托, ...