CF518D. Ilya and Escalator [概率DP]
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 <cmath>
using namespace std;
typedef unsigned long long ll;
const int N=2005;
inline int read() {
char c=getchar(); int x=0, f=1;
while(c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}
while(c>='0' && c<='9') {x=x*10+c-'0'; c=getchar();}
return x*f;
}
int n, t;
double p, f[N][N];
int main() {
freopen("in","r",stdin);
scanf("%d %lf %d", &n, &p, &t);
f[0][0]=1;
for(int i=0; i<t; i++) {
int lim = min(i, n-1);
f[i+1][n] += f[i][n];
for(int j=0; j<=lim; j++)
f[i+1][j+1] += f[i][j]*p, f[i+1][j] += f[i][j]*(1-p);
}
double ans=0;
for(int i=1; i<=n; i++) ans += i*f[t][i];
printf("%.7lf", ans);
}
Copyright:http://www.cnblogs.com/candy99/