codeforces 518D Ilya and Escalator
来源:互联网 发布:美帝 知乎 编辑:程序博客网 时间:2024/05/16 06:44
题目链接:点击打开链接
题目大意是,有n个事件,按顺序排列,每一秒,排列在最前的事件有p的概率发生,发生后移出排列。(如果之前的事件没有发生,后面的事件都不会发生,每秒只有可能发生一件事)
问t秒后发生事件的数学期望
计算每一个时间点可能发生的事件的数量的概率,dp就行。
状态转移方程为dp[i][j] = dp[i-1][j] * (1-p) + dp[i-1][j-1] * p。i表示时间,j表示已经发生的事件个数。
再用数量乘以对应概率求出期望。
#include <bits/stdc++.h>using namespace std;double dp[2005][2005];int main(){ int n,t; memset(dp,0,sizeof(dp)); double p,ans = 0; cin>>n>>p>>t; dp[1][1] = p; for(int i = 1;i <= t; i++) dp[i][0] = pow((1-p),(double)i); for(int i = 2;i <= t; i++){ for(int j = 1;j <= n&&j <= i; j ++ ){ if(i == j) dp[i][j] = pow(p,(double)i); else if(i > n && j == n){ dp[i][j] = dp[i-1][j] + dp[i-1][j-1]*p; } else{ dp[i][j] = dp[i-1][j]*(1-p) + dp[i-1][j-1]*p; } } } for(int i = 1;i <= t;i++) ans+= i*dp[t][i]; printf("%lf\n",ans); return 0;}
0 0
- codeforces 518D Ilya and Escalator
- Codeforces 518D Ilya and Escalator
- codeforces 518D D. Ilya and Escalator(概率dp)
- Codeforces 518D Ilya and Escalator (概率dp)
- Ilya and Escalator - CodeForces 518 D 概率dp
- CodeForces 518 D. Ilya and Escalator(概率DP)
- codeforces--518D--Ilya and Escalator--概率DP
- codeforces 518D. Ilya and Escalator 概率dp
- Codeforces 518D Ilya and Escalator【概率dp】
- Codeforces Round #293 (Div. 2)D. Ilya and Escalator
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator
- 【DP】 Codeforces Round #293 (Div. 2) D. Ilya and Escalator
- Codeforces Round #293 (Div. 2)-D. Ilya and Escalator
- CF 518 D. Ilya and Escalator 概率dp
- Codeforces Round #293 (Div. 2) -- D. Ilya and Escalator (DP)
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator (概率DP)
- dp(Codeforces Round #293 (Div. 2)D. Ilya and Escalator)
- 如何将PDF转换为PPT格式
- Codeforces 513C Second price auction 数学公式求期望
- Ubuntu 14.10 / Linux Mint 17.1 解决Android模拟器运行黑屏无响应的问题
- 工业控制元器件介绍
- 配合angular的框架
- codeforces 518D Ilya and Escalator
- java中的匿名内部类总结
- 笔记
- cario在virsual studio中的配置
- 技术员转型之路分析
- Android中使用webview展示html
- 常用正则表达式大全
- bzoj1069: [SCOI2007]最大土地面积 计算几何 旋转卡壳
- 【左偏树】【ZOJ 2334】Monkey King