CF 518 D. Ilya and Escalator

Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.

Let‘s assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn‘t move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him.

Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds.

Your task is to help him solve this complicated task.

Input

The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, numberp is real, given with exactly two digits after the decimal point.

Output

Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn‘t exceed 10 - 6.

Sample test(s)

input

1 0.50 1

output

0.5

input

1 0.50 4

output

0.9375

input

4 0.20 2

output

0.4

简单dpdp(i,j)表示第i分钟时,有j个人进去的概率期望=∑j*dp(t,j)

注意:递推的时候要分2种情况:队列还有人,队列已经没有人
#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>

#define LL long long
#define ULL unsigned long long

using namespace std;

const int maxn=2005;

double dp[maxn][maxn];

void solve(int ,double ,int );

int main()
{
    //loop:
    int n,t;
    double pro;
    scanf("%d %lf %d",&n,&pro,&t);
    solve(n,pro,t);
    //goto loop;
    return 0;
}

void solve(int n,double pro,int t)
{
    for(int i=0;i<maxn;i++)
        for(int j=0;j<maxn;j++)
            dp[i][j]=0.0;
    dp[0][0]=1.0;

    for(int i=1;i<=t;i++){
        dp[i][0]=dp[i-1][0]*(1.0-pro);
        for(int j=1;j<=i;j++){
            if(j<n){
                dp[i][j]=dp[i-1][j-1]*pro+dp[i-1][j]*(1.0-pro);
            }
            else if(j==n)
                dp[i][j]=dp[i-1][j-1]*pro+dp[i-1][j];
            else
                dp[i][j]=0.0;
        }
    }

    double ret=0.0;
    for(int j=0;j<=t;j++){
        ret+=dp[t][j]*j;
    }

    printf("%.10f\n",ret);
    return ;
}
				
时间: 2024-10-10 19:49:21

CF 518 D. Ilya and Escalator的相关文章

Codeforces 518D Ilya and Escalator (概率dp)

Ilya and Escalator time limit per test: 2 seconds memory limit per test: 256 megabytes Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that

Codeforces 518D Ilya and Escalator

http://codeforces.com/problemset/problem/518/D 题意:n个人,每秒有p的概率进电梯,求t秒后电梯里人数的期望 考虑dp:f[i][j]代表第i秒有j个人的概率,f[0][0]=1,f[i][j]=f[i-1][j-1]*p+f[i-1][j]*(1-p),特别有:f[i][n]=f[i-1][n]+f[i-1][n-1]*p 1 #include<cstdio> 2 #include<cmath> 3 #include<algor

Codeforces Round #293 (Div. 2) D. Ilya and Escalator (概率DP)

dp[i][j]表示第i秒电梯进去的人数为j时的概率.由于概率比较好求,而且这里的样本是有限个.所以可以先求出概率,然后用公式转化成期望. #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <

codeforces Problem-518D:Ilya and Escalator(概率dp)

传送门 题意:一共有n个人排着队,排在队首的人每一秒有p的概率上车,求过了t秒后车内的人数的期望值. 题解:用dp[i][j]表示第i秒有j个人的概率,状态转移方程为:dp[i][j]=p*dp[i-1][j-1]+(1-p)*dp[i-1][j](i<n),dp[i][j]=p*dp[i-1][j-1]+dp[i-1][j](i==n); AC代码: #include <bits/stdc++.h> using namespace std; const int maxn=2e3+4;

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 #

CF 518D(概率dp)

传送门:Ilya and Escalator 题意:有n个人排队进车厢,每秒只能进一个人,而且第1个人进了后面的人才能进,第一个人每秒进入车厢的概率为p,不进的概率为1-p,求t秒后进入车厢总人数的数学期望. 分析:设dp[i][j]表示第i秒进了j个人的概率,则: dp[i][j]=dp[i-1][j]*(1-p)+dp[i-1][j-1]*p. 注意边界限制: 当j=0时:dp[i][j]=dp[i-1][j]*(1-p) 当j=n时:dp[i][j]=dp[i-1][j]+dp[i-1][

Codeforces Round #293 (Div. 2)

 A Vitaly and Strings 题意:给定长度相等的字符串s,t,且s的字典序小于t,求一个字符串q字典序大于s小于t. 分析:将字符串看做26进制的数,对s”+1“即可. #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define esp 1e-14 #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #defi

CF 842C Ilya And The Tree(树上DFS)

题目链接:http://codeforces.com/problemset/problem/842/C 题目: Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the

/etc/postfix/main.cf

# cat main.cf     1  # Global Postfix configuration file. This file lists only a subset     2  # of all parameters. For the syntax, and for a complete parameter     3  # list, see the postconf(5) manual page (command: "man 5 postconf").     4  #