1. 程式人生 > >【Henu ACM Round#15 D】Ilya and Escalator

【Henu ACM Round#15 D】Ilya and Escalator

mat con .com color fine using 沒有 () 轉移

【鏈接】 我是鏈接,點我呀:)
【題意】


在這裏輸入題意

【題解】


概率DP;
設f[i][j]表示前i個單位時間,j個人進入房間的概率是多少
然後想一下和i-1秒的時候要怎麽轉移就可以了。
i-1秒可能進入了一個人->f[i][j]+=f[i-1][j-1]p
i-1秒沒有人進去->
①已經有n個人了,f[i][j] += f[i-1][j]
②還沒有n個人(j<n) f[i][j]+=f[i-1][j]
(1-p)
最後答案就是\(∑_1^nf[t][i]*i\)

【代碼】

#include <bits/stdc++.h>
using namespace
std; const int N = 2000+10; double f[N][N]; //f[i][j]????i??,j??????????? int n;double p;int t; int main() { ios::sync_with_stdio(0),cin.tie(0); #ifdef LOCAL_DEFINE freopen("rush.txt","r",stdin); #endif cin >> n >> p >> t; f[0][0] = 1; for
(int i = 1;i <= t;i++) for (int j = 0;j <= n;j++){ if (j==n){ f[i][j] += f[i-1][j]; }else f[i][j] += f[i-1][j]*(1-p); if (j>0){ f[i][j] += f[i-1][j-1]*p; } } double ans = 0; for
(int i = 0;i <= n;i++){ ans+=f[t][i]*i; } cout <<fixed<<setprecision(10)<< ans << endl; return 0; }

【Henu ACM Round#15 D】Ilya and Escalator