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.
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.
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.
1 0.50 1
0.5
1 0.50 4
0.9375
4 0.20 2
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的更多相关文章
- Codeforces 518 D Ilya and Escalator
Discription Ilya got tired of sports programming, left university and got a job in the subway. He wa ...
- D. Ilya and Escalator
D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- CF518D. Ilya and Escalator [概率DP]
CF518D. Ilya and Escalator 题意:n个人,每秒p的概念队首的人进入电梯,求t秒后期望人数 直接使用期望定义 \(f[i][j]\) i秒后电梯中j个人的概率 注意n个人的时候 ...
- 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 ...
- Codeforces 518D Ilya and Escalator
http://codeforces.com/problemset/problem/518/D 题意:n个人,每秒有p的概率进电梯,求t秒后电梯里人数的期望 考虑dp:f[i][j]代表第i秒有j个人的 ...
- ●CodeForces 518D Ilya and Escalator
题链: http://codeforces.com/problemset/problem/518/D题解: 期望dp. 定义dp[t][i]表示在第t秒开始之前,已经有了i个人在电梯上,之后期望能有多 ...
- Codeforces518 D. Ilya and Escalator
传送门:>Here< 题意:有n个人排队做电梯,每个人必须等前面的人全部上了以后才能上.对于每秒钟,有p的概率选择上电梯,(1-p)的概率选择不上电梯.现在问t秒期望多少人上电梯 解题思路 ...
- CoderForces 518D Ilya and Escalator (期望DP)
题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的 ...
- 【Henu ACM Round#15 D】Ilya and Escalator
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 概率DP; 设f[i][j]表示前i个单位时间,j个人进入房间的概率是多少 然后想一下和i-1秒的时候要怎么转移就可以了. i-1秒 ...
随机推荐
- phpmyadmin的安装和使用
首先在phpmyadmin的官方网站的下载页面根据自己的PHP以及MYSQL的版本下载对应的phpmyadmin版本. 图中红框部分标识此版本支持度额PHP版本以及MYADL版本. 比如此版本就是支持 ...
- Java——匿名内部类
/* * 匿名内部类, 就是内部类的简写形式. * * 必须有前提: * 内部类必须继承或者实现一个外部类或者接口. * 匿名内部类其实就是一个子类对象. * * 格式:new 父类or接 ...
- spring源码学习【准备】之jdk动态代理和cglib动态代理的区别和性能
一:区别:---->JDK的动态代理依靠接口实现,如果有些类并没有实现接口,则不能使用JDK代理,这就要使用cglib动态代理了.--->JDK的动态代理机制只能代理实现了接口的类,而不能 ...
- gcc: multiple definition of [转]
/home/tace/openav/source/SeamlessMessage/CPaoFlt.o: In function `CPaoFlt::get_m_strPrmair() const':C ...
- Android TextView内容过长加省略号,点击显示全部内容
在Android TextView中有个内容过长加省略号的属性,即ellipsize,用法如下: 在xml中:android:ellipsize="end" 省略号在结尾an ...
- WCF Restful JQuery 跨域解决方法
<?xml version="1.0"?> <!-- For more information on how to configure your ASP.NET ...
- 二十四种设计模式:适配器模式(Adapter Pattern)
适配器模式(Adapter Pattern) 介绍将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作.示例有一个Message实体类 ...
- AngularJS 的安全Apply
$scope.safeApply = function(fn) { var phase = this.$root.$$phase; if (phase == ‘$apply‘ || p ...
- css之opacity
设置div元素的不透明级别 语法: value :从0.0(完全透明)到1.0(完全不透明) inherit:应该从父元素继承opacity属性 z-index 属性设置元素的堆叠顺序,仅能在定位元素 ...
- 透明度兼容性(ie8以上)
转载:http://www.cnblogs.com/PeunZhang/p/4089894.html demo代码:文件中,背景透明,文字不透明的研究和使用.zip