【Henu ACM Round#15 D】Ilya and Escalator

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

概率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;
}
原文地址:https://www.cnblogs.com/AWCXV/p/8350793.html