概率dp- Ilya and Escalator
来源:互联网 发布:秦美人四灵进阶数据 编辑:程序博客网 时间:2024/06/10 04:32
题目
cf518D
大致意思是一个由n个人组成的队列,每个单位时刻队列头可以选择出队列概率为p,或者是不出队列,概率为1-p. 问过了t个单位时刻, 出队列的人数的期望。
思路
如果能计算出
P{X=i}(0<=i<=t) 那么就能解决这个问题了。 答案就是∑i=0nP{X=i}∗i
对于P{X=i}
设dp[i][j] 表示前t个单位时刻,有j个人出队列的概率。
那么
dp[i+1][j+1] += dp[i][j] * P
dp[i+1][j] += dp[i][j] * (1 - P)
当j >= n的时候 dp[i+1][j] += dp[i][j]
代码
#include <cstring>#include <stdio.h>#include <algorithm>using namespace std;int N,T;double P;const int maxn = 2010;double dp[maxn][maxn];int main() { scanf("%d%lf%d",&N,&P,&T); for(int i = 0;i <= T;i ++) { for(int j = 0;j <= N;j ++) { dp[i][j] = 0.0; } } dp[0][0] = 1.0; for(int i = 0;i <= T;i ++) { for(int j = 0;j <= i;j ++) { if(j >= N) { dp[i+1][j] += dp[i][j]; continue; } dp[i+1][j+1] += dp[i][j] * P; dp[i+1][j] += dp[i][j] * (1 - P); } } double ret = 0.0; for(int i = 1;i <= N;i ++) { ret += dp[T][i] * i; } printf("%f\n",ret);}
0 0
- 概率dp- Ilya and Escalator
- Codeforces 518D Ilya and Escalator (概率dp)
- Ilya and Escalator - CodeForces 518 D 概率dp
- CodeForces 518 D. Ilya and Escalator(概率DP)
- codeforces 518D D. Ilya and Escalator(概率dp)
- codeforces--518D--Ilya and Escalator--概率DP
- codeforces 518D. Ilya and Escalator 概率dp
- CF 518 D. Ilya and Escalator 概率dp
- Codeforces 518D Ilya and Escalator【概率dp】
- Codeforces Round #293 (Div. 2) 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
- Codeforces Round #293 (Div. 2) -- D. Ilya and Escalator(概率DP)
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator(概率DP)
- Ilya and Escalator-python
- 【DP】 Codeforces Round #293 (Div. 2) D. Ilya and Escalator
- codeforces 518D Ilya and Escalator
- Codeforces 518D Ilya and Escalator
- [LeetCode] 158. Read N Characters Given Read4 II - Call multiple times
- Cocos2d-x中ImageView的使用
- 9 集合
- 个人笔记 css 03 设置表格显示外边框
- spark streaming---使用gradle混合编译Scala和Java项目并打包
- 概率dp- Ilya and Escalator
- QT检测客户端
- 分布式网站架构后续:zookeeper技术浅析
- poj 1251 Jungle Roads(最小生成树)
- LeetCode198. House Robber
- 【推荐】大规模的自然场景文字检测与识别数据库
- AC自动机入门
- LeetCode213. House Robber II
- CentOS 命令登录MySQL时,报错 ERROR 1045 (28000): Access denied for user root@localhost (using password: NO)