Codeforces518 D. Ilya and Escalator】的更多相关文章

传送门:>Here< 题意:有n个人排队做电梯,每个人必须等前面的人全部上了以后才能上.对于每秒钟,有p的概率选择上电梯,(1-p)的概率选择不上电梯.现在问t秒期望多少人上电梯 解题思路: 期望DP. $f[i][j]$表示第i秒上了j个人的概率. $f[1][1] = p, f[1][0] = (1 - p)$,并且$f[i][0]$都需要初始化.($* (1 - p)$) 这题好像和普通的期望DP不太一样啊,因为f数组设的是概率而不是期望.这样设的话答案就应该是$\sum\limits_…
D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine…
CF518D. Ilya and Escalator 题意:n个人,每秒p的概念队首的人进入电梯,求t秒后期望人数 直接使用期望定义 \(f[i][j]\) i秒后电梯中j个人的概率 注意n个人的时候直接\(f[i][n] \rightarrow f[i+1][n]\) #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmat…
D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine…
Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following…
Discription Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the tw…
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 #include<cstdio> #include<cmath> #include<algorithm&g…
题链: http://codeforces.com/problemset/problem/518/D题解: 期望dp. 定义dp[t][i]表示在第t秒开始之前,已经有了i个人在电梯上,之后期望能有多少人上电梯. 转移: dp[t][i]=(1-P)*dp[t+1][i]+P*(dp[t+1][i+1]+1) 代码: #include<bits/stdc++.h> #define MAXN 2005 using namespace std; int N,T; double P,dp[MAXN]…
题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的概率,有两种情况,要么第 i-1 时刻已经有 j 个人了,那么就不进,要么第 i-1 时刻只有 j-1个人,就得进入, 也就是d[i][j] = d[i-1][j] * (1-P) + d[i-1][j-1] * p;这就是状态转移方程,最重要的是有一种情况一定要注意...那就是当第 i-1 时刻已…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 概率DP; 设f[i][j]表示前i个单位时间,j个人进入房间的概率是多少 然后想一下和i-1秒的时候要怎么转移就可以了. i-1秒可能进入了一个人->f[i][j]+=f[i-1][j-1]p i-1秒没有人进去-> ①已经有n个人了,f[i][j] += f[i-1][j] ②还没有n个人(j<n) f[i][j]+=f[i-1][j](1-p) 最后答案就是\(∑_1^nf[t][i]*i\) [代码] #incl…