CF 518D (Ilya and Escalator-Take Dp directly if the number of combinations is too large), 518 dilya

Source: Internet
Author: User

CF 518D (Ilya and Escalator-Take Dp directly if the number of combinations is too large), 518 dilya

D. Ilya and Escalatortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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 thatNPeople 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 probabilityP, Or the first person in the queue doesn't move with probability (1 hour-Snapshot-P), Paralyzed by his fear of escalators and making the whole queue wait behind him.

Formally speaking,I-Th person in the queue cannot enter the escalator until people with indices from 1IAccept-limit 1 additional sive 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 afterTSeconds.

Your task is to help him solve this complicated task.

Input

The first line of the input contains three numbersN, Bytes,P, Bytes,T(1 digit ≤ DigitN, Bytes,TLimit ≤ limit 2000, 0 limit ≤ limitPLimit ≤ limit 1). NumbersNAndTAre integers, numberPIs 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 afterTSeconds. The absolute or relative error mustn't exceed 10 seconds-limit 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

I want to askCombination number CIt is found that C () is too large.

So the competition was not done ....

The result isDp!!

It makes sense... Next note



#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXN (2000+10)#define eps (1e-7)long long mul(long long a,long long b){return (a*b)%F;}long long add(long long a,long long b){return (a+b)%F;}long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}typedef long long ll;int n,t;double p;long double f[MAXN][MAXN]={0}; int main(){//freopen("Escalator.in","r",stdin);//freopen(".out","w",stdout);cin>>n>>p>>t;if (n>=t){cout<<p*t<<endl;return 0;}f[0][0]=1;Rep(i,t+1)Rep(j,min(i,n)+1){if (j==n) f[i+1][j]+=f[i][j];else{f[i+1][j+1]+=f[i][j]*p;f[i+1][j]+=f[i][j]*(1-p);}}double ans=0;Rep(j,n+1) ans+=f[t][j]*min(j,n);printf("%.10lf\n",ans);return 0;}



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.