首页 > 其他 > 详细

Codeforces 518D Ilya and Escalator

时间:2016-06-28 18:20:02      阅读:91      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/qzqzgfy/p/5624249.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!