https://codeforces.com/problemset/problem/518/D
アイデア:
dp [t] [j]を、人jがt秒までにエレベータに乗る確率として定義します。
転送:
dp [t] [j] = dp [t-1] [j-1] * p + dp [t-1] [j] *(1-p);
境界:j == 0の場合でも、転送には*(1-p)が必要です。
j == nの場合、前者の転送は100%です。
答えはans + = dp [t] [j:0〜n] * jです。
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
double dp[maxn][maxn];///到t秒 j个人上了电梯的概率
int main(void)
{
///cin.tie(0);std::ios::sync_with_stdio(false);
LL n,t;double p;
n=read();
scanf("%lf",&p);
t=read();
dp[1][0]=1.0-p;
dp[1][1]=1.0*p;
for(LL i=2;i<=t;i++){///枚举时间
for(LL j=0;j<=n;j++){///枚举人
if(j==0) dp[i][j]=dp[i-1][j]*(1-p);
else if(j==n) dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*p;
else dp[i][j]=dp[i-1][j-1]*p+dp[i-1][j]*(1.0-p);
}
}
double ans=0;
for(LL j=0;j<=n;j++){
ans+=1.0*j*dp[t][j];
}
printf("%.8f\n",ans);
return 0;
}