CF 518 D. Ilya and Escalator

Source: Internet
Author: User

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

Let's assume that n people stand in the queue for the escalator. At all second one of the following possibilities takes place:either the first person in the queue enters the Escalat or with probability p, or the first person in the queue doesn ' t move with probability (1- P), p Aralyzed 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, which is he'll be standing on the escalator at a NY 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 TS after the decimal point.

Output

Print a single real number-the expected number of people who'll be standing on the escalator after T s Econds. The absolute or relative error mustn ' t exceed 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


Simple DP
DP (I,J) indicates the probability that a J person would go in the first minute.
Expected =∑J*DP (T,J)

Note: There are 2 things to do when you push a recursive step:
The queue is still manned, the queue has no one




#include <cstdio>#include<cstring>#include<vector>#include<iostream>#include<algorithm>#include<stack>#include<queue>#defineLL Long Long#defineULL unsigned long Longusing namespacestd;Const intmaxn=2005;DoubleDP[MAXN][MAXN];voidSolveint,Double,int );intMain () {//Loop:    intn,t; DoublePro; scanf ("%d%lf%d",&n,&pro,&t);    Solve (n,pro,t); //Goto Loop;    return 0;}voidSolveintNDoubleProintt) {     for(intI=0; i<maxn;i++)         for(intj=0; j<maxn;j++) Dp[i][j]=0.0; dp[0][0]=1.0;  for(intI=1; i<=t;i++) {dp[i][0]=dp[i-1][0]*(1.0-Pro);  for(intj=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]; ElseDp[i][j]=0.0; }    }    Doubleret=0.0;  for(intj=0; j<=t;j++) {ret+=dp[t][j]*J; } printf ("%.10f\n", ret); return ;}




CF 518 D. Ilya and Escalator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.