0
点赞
收藏
分享

微信扫一扫

CF 518D(Ilya and Escalator-组合数太大,就直接拿去Dp)



D. Ilya and Escalator



time limit per test



memory limit per test



input



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.

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.

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

Your task is to help him solve this complicated task.



Input



n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p



Output



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



本题我想求组合数C 发现 C(2000,1000)太大。

于是比赛没做出来。。。。

结果居然只是dp!!

很有道理。。。下次注意



#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;
}




举报

相关推荐

0 条评论