【codeforces 768F】 Barrels and boxes
生活随笔
收集整理的這篇文章主要介紹了
【codeforces 768F】 Barrels and boxes
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
http://codeforces.com/problemset/problem/768/F?(題目鏈接)
題意
A,B兩種物品可以裝到棧中,每個棧只能存放一種物品,容量沒有限制。現(xiàn)在講所有棧排成一列,AB相間,問存B的棧長大于H的概率。
Solution
震驚!F竟是個大水題。。。枚舉長度隔板法搞一搞就好了。。
細節(jié)
注意判0分成0組的情況?LL
代碼
// codeforces768F #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #define LL long long #define inf 2147483640 #define MOD 1000000007 #define Pi acos(-1.0) #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); using namespace std;const int maxn=100010; LL fac[maxn],ifac[maxn]; int F,W,H,n; LL P,Q;LL C(LL n,LL m) {if (n==m && n==-1) return 1;return n<0||m<0||n<m ? 0 : fac[n]*ifac[m]%MOD*ifac[n-m]%MOD; } LL power(LL a,LL b) {LL res=1;while (b) {if (b&1) (res*=a)%=MOD;b>>=1;(a*=a)%=MOD;}return res; } int main() {scanf("%d%d%d",&F,&W,&H);n=F+W;fac[0]=1;for (int i=1;i<=100000;i++) fac[i]=fac[i-1]*i%MOD;ifac[100000]=power(fac[100000],MOD-2);for (int i=100000;i;i--) ifac[i-1]=ifac[i]*i%MOD;for (int i=1;i<=n;i++) {int w=(i&1) ? 1 : 2;for (int j=i>>1;j<=(i+1)>>1;j++) {LL q=C(F-1,j-1)*C(W-1,i-j-1)%MOD*w%MOD;LL p=C(F-1,j-1)*C(W-1LL*(i-j)*H-1,i-j-1)%MOD*w%MOD;(Q+=q)%=MOD,(P+=p)%=MOD;}}printf("%lld",P*power(Q,MOD-2)%MOD);return 0; }
轉(zhuǎn)載于:https://www.cnblogs.com/MashiroSky/p/6553934.html
總結(jié)
以上是生活随笔為你收集整理的【codeforces 768F】 Barrels and boxes的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python之第一个helloworld
- 下一篇: [BZOJ3998][TJOI2015]