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

简单dp
dp(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=; 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 ;
} void solve(int n,double pro,int t)
{
for(int i=;i<maxn;i++)
for(int j=;j<maxn;j++)
dp[i][j]=0.0;
dp[][]=1.0; for(int i=;i<=t;i++){
dp[i][]=dp[i-][]*(1.0-pro);
for(int j=;j<=i;j++){
if(j<n){
dp[i][j]=dp[i-][j-]*pro+dp[i-][j]*(1.0-pro);
}
else if(j==n)
dp[i][j]=dp[i-][j-]*pro+dp[i-][j];
else
dp[i][j]=0.0;
}
} double ret=0.0;
for(int j=;j<=t;j++){
ret+=dp[t][j]*j;
} printf("%.10f\n",ret);
return ;
}

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

  1. Codeforces 518 D Ilya and Escalator

    Discription Ilya got tired of sports programming, left university and got a job in the subway. He wa ...

  2. D. Ilya and Escalator

    D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. CF518D. Ilya and Escalator [概率DP]

    CF518D. Ilya and Escalator 题意:n个人,每秒p的概念队首的人进入电梯,求t秒后期望人数 直接使用期望定义 \(f[i][j]\) i秒后电梯中j个人的概率 注意n个人的时候 ...

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

    D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. Codeforces 518D Ilya and Escalator

    http://codeforces.com/problemset/problem/518/D 题意:n个人,每秒有p的概率进电梯,求t秒后电梯里人数的期望 考虑dp:f[i][j]代表第i秒有j个人的 ...

  6. ●CodeForces 518D Ilya and Escalator

    题链: http://codeforces.com/problemset/problem/518/D题解: 期望dp. 定义dp[t][i]表示在第t秒开始之前,已经有了i个人在电梯上,之后期望能有多 ...

  7. Codeforces518 D. Ilya and Escalator

    传送门:>Here< 题意:有n个人排队做电梯,每个人必须等前面的人全部上了以后才能上.对于每秒钟,有p的概率选择上电梯,(1-p)的概率选择不上电梯.现在问t秒期望多少人上电梯 解题思路 ...

  8. CoderForces 518D Ilya and Escalator (期望DP)

    题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的 ...

  9. 【Henu ACM Round#15 D】Ilya and Escalator

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 概率DP; 设f[i][j]表示前i个单位时间,j个人进入房间的概率是多少 然后想一下和i-1秒的时候要怎么转移就可以了. i-1秒 ...

随机推荐

  1. nginx和apache下的url rewrite

    将服务器上面的数据同步到本地之后,发现打开首页显示不正常,本地服务器是apache,经过打开url rewrite之后本地首页正常显示. 原因是phpwind本身支持了url rewrite的功能,但 ...

  2. 关于for,while与do while

    Q:输入一个整数i,输出i+(i+1)+...+19+20的结果 S:法1:for #include<stdio.h> #include<math.h> #include< ...

  3. 利用CSS的@font-face属性 在网页中嵌入字体

    字体使用是网页设计中不可或缺的一部分.网页是文字的载体,我们希望在网页中使用某一特定字体,但是该字体并非主流操作系统的内置字体,这样用户在浏览页面的时候就有可能看不到真实的设计. 美工设计师最常做的办 ...

  4. SVM实用操作: svmtrain and svmclassify

    load fisheriris data = [meas(:,), meas(:,)]; groups = ismember(species,'setosa'); [train, test] = cr ...

  5. SpringMVC @Value取值(取properties属性文件的属性值)

    @Controller @RequestMapping("/reg") public class RegController extends BaseController { @V ...

  6. javascript面向对象规则汇总以及json

    javascript中一切皆对象,而且定义非常灵活, 于是出现了一些相对其他编程语言环境下匪夷所思的代码: ---------------------------------------------- ...

  7. 锁_rac环境kill锁表会话后出现killed状态(解决)

    原创作品,出自 "深蓝的blog" 博客,深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/46876961 ra ...

  8. linux重启和关闭系统命令

    重启命令: 1.reboot 2.shutdown -r now 立刻重启(root用户使用) 3.shutdown -r 10 过10分钟自动重启(root用户使用) 4.shutdown -r 2 ...

  9. jQuery.fn.extend与jQuery.extend

    jQuery.extend(),是扩展的jQuery这个类. 假设我们把jQuery这个类看成是人类,能吃饭能喝水能跑能跳,现在我们用jQuery.extend这个方法给这个类拓展一个能唱歌的技能.这 ...

  10. CARP-VRRP-HSRP

    CARP-VRRP-HSRP http://www.openbsd.org/faq/pf/carp.html