Codeforces Round #293 (Div. 2) D. Ilya and Escalator
先求出概率
设 \(f_{i,j}\) 表示第 \(i\) 秒电梯上有 \(j\) 个人的概率
则 \(f_{0,0}=1\)
\(f_{i + 1, j + 1} = f_{i, j} \times p\)
\(f_{i + 1, j} = f_{i, j} \times (1 - p)\)
\(f_{i+1,n}=f_{i,n}\)
答案即为 \(\sum f_{t, i} \times i\)
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define lp p << 1
#define rp p << 1 | 1
#define mid ((l + r) >> 1)
#define ll long long
#define db double
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define Edg int cnt=1,head[N],to[N*2],ne[N*2];void addd(int u,int v){to[++cnt]=v;ne[cnt]=head[u];head[u]=cnt;}void add(int u,int v){addd(u,v);addd(v,u);}
#define Edgc int cnt=1,head[N],to[N*2],ne[N*2],c[N*2];void addd(int u,int v,int w){to[++cnt]=v;ne[cnt]=head[u];c[cnt]=w;head[u]=cnt;}void add(int u,int v,int w){addd(u,v,w);addd(v,u,w);}
#define es(u,i,v) for(int i=head[u],v=to[i];i;i=ne[i],v=to[i])
const int N = 2e3 + 7;
db f[N][N];
int main() {
int n, t;
db p;
scanf("%d%lf%d", &n, &p, &t);
f[0][0] = 1;
rep(i, 0, t) {
f[i + 1][n] = f[i][n];
rep(j, 0, n) if (f[i][j]) {
f[i + 1][j] += f[i][j] * (1.0 - p);
f[i + 1][j + 1] += f[i][j] * p;
}
}
db ans = 0;
rep(i, 0, n + 1) ans += f[t][i] * i;
printf("%.7f\n", ans);
return 0;
}