Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) F
2017-02-22 19:40
615 查看
题意:
Tarly有f个食物箱和w个酒桶,现在他想要将它们存在一些栈里,然后将这些栈排成一行,要求满足任意相邻的两个栈存放的物品不同
而Jon Snow不喜欢每个存酒的栈里酒的数量小于等于h,问在满足以上限制的前提下出现可行解的概率为多少?(假设每种满足Tarly要求的摆放方案出现的概率均等)
0 <= f,w,h <= 1E5 答案mod 1E9 + 7输出
solution:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 2E5 + 20;
typedef long long LL;
const LL mo = 1000000007;
int f,w,h,t,Ans,tot,Fac[maxn],Inv[maxn];
int Mul(const LL &x,const LL &y) {return x * y % mo;}
int Add(const int &x,const int &y) {return (x + y) % mo;}
int ksm(int x,int y)
{
int ret = 1;
for (; y; y >>= 1)
{
if (y & 1) ret = Mul(ret,x);
x = Mul(x,x);
}
return ret;
}
int C(int N,int M)
{
return Mul(Fac
,Mul(Inv[M],Inv[N - M]));
}
int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif
cin >> f >> w >> h; Fac[0] = 1;
if (!w) {cout << 1 << endl; return 0;}
++h; t = w / h;
if (w < h) {cout << 0 << endl; return 0;}
for (int i = 1; i <= f + w; i++) Fac[i] = Mul(Fac[i - 1],i);
Inv[f + w] = ksm(Fac[f + w],mo - 2);
for (int i = f + w - 1; i >= 0; i--) Inv[i] = Mul(Inv[i + 1],i + 1);
tot = ksm(C(f + w,f),mo - 2);
for (int i = 1; i <= min(f + 1,t); i++)
Ans = Add(Ans,Mul(C(f + 1,i),C(w - i * h + i - 1,i - 1)));
cout << Mul(Ans,tot) << endl;
return 0;
}
Tarly有f个食物箱和w个酒桶,现在他想要将它们存在一些栈里,然后将这些栈排成一行,要求满足任意相邻的两个栈存放的物品不同
而Jon Snow不喜欢每个存酒的栈里酒的数量小于等于h,问在满足以上限制的前提下出现可行解的概率为多少?(假设每种满足Tarly要求的摆放方案出现的概率均等)
0 <= f,w,h <= 1E5 答案mod 1E9 + 7输出
solution:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 2E5 + 20;
typedef long long LL;
const LL mo = 1000000007;
int f,w,h,t,Ans,tot,Fac[maxn],Inv[maxn];
int Mul(const LL &x,const LL &y) {return x * y % mo;}
int Add(const int &x,const int &y) {return (x + y) % mo;}
int ksm(int x,int y)
{
int ret = 1;
for (; y; y >>= 1)
{
if (y & 1) ret = Mul(ret,x);
x = Mul(x,x);
}
return ret;
}
int C(int N,int M)
{
return Mul(Fac
,Mul(Inv[M],Inv[N - M]));
}
int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif
cin >> f >> w >> h; Fac[0] = 1;
if (!w) {cout << 1 << endl; return 0;}
++h; t = w / h;
if (w < h) {cout << 0 << endl; return 0;}
for (int i = 1; i <= f + w; i++) Fac[i] = Mul(Fac[i - 1],i);
Inv[f + w] = ksm(Fac[f + w],mo - 2);
for (int i = f + w - 1; i >= 0; i--) Inv[i] = Mul(Inv[i + 1],i + 1);
tot = ksm(C(f + w,f),mo - 2);
for (int i = 1; i <= min(f + 1,t); i++)
Ans = Add(Ans,Mul(C(f + 1,i),C(w - i * h + i - 1,i - 1)));
cout << Mul(Ans,tot) << endl;
return 0;
}
相关文章推荐
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)
- 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)
- 【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索
- 【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
- 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A(贪心)
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1(DFS好题)
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E
- 【Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B】 Code For 1
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)
- Editorial Divide by Zero and Codeforces Round #399 (Div. 1+2, combined) (A~F)
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E
- 【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals