DP[i][j]表示前i時間內進入j個人的概率,那麼期望就是 DP[t][i]*i 的和;
DP[i][j] = DP[i-1][j]*(1.0-p) + DP[i-1][j-1]*p;
特例:當 j == n時,已經沒有人在等待了,說以DP[i][j] = DP[i-1][j] + DP[i-1][j-1]*p;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
const int maxn = 2000 + 7;
double dp[maxn][maxn], p;
int n, t;
int main() {
scanf("%d%lf%d", &n, &p, &t);
memset(dp, 0, sizeof(dp));
double ans = 0.0;
dp[0][0] = 1.0;
for(int i = 1; i <= t; ++i) {
for(int j = 0; j < n; ++j)
dp[i][j] = dp[i-1][j]*(1.0-p) + dp[i-1][j-1]*p;
dp[i][n] = dp[i-1][n] + dp[i-1][n-1]*p;
}
for(int i = 1; i <= n; ++i) ans += dp[t][i]*i;
printf("%.6lf\n", ans);
}