Codeforces 518D Ilya and Escalator
Posted GFY
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 518D Ilya and Escalator相关的知识,希望对你有一定的参考价值。
http://codeforces.com/problemset/problem/518/D
题意:n个人,每秒有p的概率进电梯,求t秒后电梯里人数的期望
考虑dp:f[i][j]代表第i秒有j个人的概率,f[0][0]=1,f[i][j]=f[i-1][j-1]*p+f[i-1][j]*(1-p),特别有:f[i][n]=f[i-1][n]+f[i-1][n-1]*p
1 #include<cstdio> 2 #include<cmath> 3 #include<algorithm> 4 #include<cstring> 5 #include<iostream> 6 double p,f[2005][2005]; 7 int n,t; 8 int read(){ 9 int t=0,f=1;char ch=getchar(); 10 while (ch<‘0‘||ch>‘9‘){if (ch==‘-‘) f=-1;ch=getchar();} 11 while (‘0‘<=ch&&ch<=‘9‘){t=t*10+ch-‘0‘;ch=getchar();} 12 return t*f; 13 } 14 int main(){ 15 double p; 16 n=read();scanf("%lf",&p);t=read(); 17 f[0][0]=1; 18 for (int i=1;i<=t;i++){ 19 for (int j=0;j<n;j++) 20 f[i][j]=f[i-1][j]*(1-p)+f[i-1][j-1]*p; 21 f[i][n]=f[i-1][n]+f[i-1][n-1]*p; 22 } 23 double ans=0; 24 for (int i=1;i<=n;i++) 25 ans+=f[t][i]*i; 26 printf("%.6f\n",ans); 27 return 0; 28 }
以上是关于Codeforces 518D Ilya and Escalator的主要内容,如果未能解决你的问题,请参考以下文章
codeforces 842C Ilya And The Tree
Ilya And The Tree CodeForces - 842C
C - Ilya And The Tree Codeforces Round #430 (Div. 2)
Codeforces Round #293 (Div. 2) D. Ilya and Escalator