D. Ilya and Escalator
2 seconds
256 megabytes
standard input
standard 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 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, number p 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
题目抽象:n个人排队上电梯,排头每秒上去的概率为p,一共t秒,求t秒都电梯内人数的期望。
思路:简单的概率dp,dp[i][j]表示第i秒电梯上有j个人的概率,最后累计一下期望
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
const int INF=0x7fffffff;
const double EXP=1e-;
const int MS=;
const int mod=;
typedef long long LL;
double dp[MS][MS];
// dp[i][j] 在i second 的时间内 进入 了j个人的概率, /// dp[i-1][n-1]*p
// dp[i][n]
// dp[i-1][n]*1; int main()
{ int n,t,i,j;
double p,ans=;
memset(dp,,sizeof(dp));
dp[][]=1.0;
cin>>n>>p>>t;
for(i=;i<t;i++)
{
for(j=;j<n;j++)
{
dp[i+][j+]+=dp[i][j]*p;
dp[i+][j]+=dp[i][j]*(-p);
}
dp[i+][n]+=dp[i][n];
//特别注意这里。 因为n特殊一点
// dp[i][n-1]*p
// dp[i+1][n]
// dp[i][n]*p;
}
for(i=;i<=n;i++)
ans+=i*dp[t][i];
cout<<setiosflags(ios::fixed)<<setprecision()<<ans<<endl;
return ;
}
D. Ilya and Escalator的更多相关文章
- 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 ...
- 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 ...
- Codeforces 518 D Ilya and Escalator
Discription Ilya got tired of sports programming, left university and got a job in the subway. He wa ...
- 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秒 ...
随机推荐
- 第二百二十二天 how can I 坚持
纪念碑谷好费脑子啊,头都大了,被遗忘的海最后百度了下攻略才过了. 今天下班遇到了易军,哎,总感觉怪怪的,心情顿时压抑了些,源二生日,一起去吃了个饭,烤鸭,吃的挺不错. 创新去哪了,其实每个人的内心深处 ...
- Dagger2学习资源
文章 Jack Wharton关于Dagger的幻灯片 代码 用Dagger2改写Jack Wharton的U+2020 我自己写的,包含了dagger2和单元测试 chiuki写的,包含了dagge ...
- POJ 3304 Segments (直线和线段相交判断)
Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7739 Accepted: 2316 Descript ...
- OSPF虚链路配置.示例2
先看一个拓扑图 黄色区域是area0,即骨干区域,如果如图示RT1与RT6之间的链路断了,那么会出现骨干区域被“分裂”的情况,很明显骨干区域是不能被分割开的,出现这种状况的时候可能会影响到整个自制系统 ...
- 使用JAP(基类)父类注解
-----------------基类------------------------------- /** * @className:com.jubangit.ebusiness.database. ...
- 安装、设置与启动MySql5.1.30绿色版的方法
1.解压 mysql-noinstall-5.1.30-win32.zip(下载地址http://dev.mysql.com/downloads/mysql/5.1.html) 2.在 F 盘建立目录 ...
- 浏览器判断及IE版本区分
备注:在火狐下和IE下,js的执行不一致,很多语句结果不一致,其他浏览器也可能,注意验证,多用if else包括window.onload: ①只用来区分IE和非IE内核的浏览器,由于只有IE支持Ac ...
- 个人分享:平时开发中感觉几款不错 IDE 、插件、工具
本人主业 C# 开发,由于是做 Web 开发,所以像 SQL.JavaScript 这些肯定经常要接触到.当然,平时本人也写过 Node.js.Java.Python之类,不过,这些只能讲简单了解而已 ...
- Oracle 建表常用数据类型的详解
创建表时,必须为表的各个列指定数据类型.如果实际的数据与该列的数据类型不相匹配,则数据库会拒绝保存.如为学生指定出生日期为“1980-13-31”. 在Oracle中,常见的数据类型有: 字符串:字符 ...
- SAE/ISO standards for Automotive
On-Board Diagnostics J1962 Diagnostic Connector Equivalent to ISO/DIS 15031-3: December 14, 2001J201 ...