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 }

 

转载于:https://www.cnblogs.com/qzqzgfy/p/5624249.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值