●CodeForces 518D Ilya and Escalator
题链:
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][MAXN]; int main(){ ios::sync_with_stdio(0); cin>>N>>P>>T; for(int t=T;t>=1;t--) for(int i=0;i<N;i++) dp[t][i]=(1-P)*dp[t+1][i]+P*(dp[t+1][i+1]+1); cout<<fixed<<setprecision(6)<<dp[1][0]<<endl; return 0; }
Do not go gentle into that good night.
Rage, rage against the dying of the light.
————Dylan Thomas