[题解] [CF518D] Ilya and Escalator】的更多相关文章

题面 题解 期望dp入门题 设\(f[i][j]\)为到\(i\)时间有\(j\)个人上了电梯的概率, 我们可以得到转移方程 \[ f[i][j]=\begin{cases}f[i-1][j]\cdot(1-p),&j=0\\f[i-1][j-1]\cdot p+f[i-1][j]\cdot(1-p),&j\in[1,n)\\f[i-1][n]+f[i-1][n-1]\cdot p,&j=n\end{cases} \] Code #include <algorithm>…
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…
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题解: 期望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]…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 概率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…
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…
传送门:>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_…