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秒 ...
随机推荐
- windows 7 获取SYSTEM权限
当Adobe Reader 9.0卸载之后,你会发现原来的C:\Program Files\Adobe\Reader 9.0\Resource\CMap文件夹下的一些文件无法删除,提示你需要SYSTE ...
- [iOS微博项目 - 2.3] - 用户取消对app的授权
github: https://github.com/hellovoidworld/HVWWeibo A.用户取消对app的授权 用户可以在微博网站上取消对某个应用(app)的授权 1.打开& ...
- POJ1651Multiplication Puzzle(区间DP)
比较好做的区间DP 状态转移方程:DP[i][j] 表示区间[i,j]最小的乘积和. DP[i][j] = MIN{DP[i][k-1]+DP[k+1][j] + a[k]*a[i-1]*a[j+1] ...
- 开机自动播放音乐的vbs
今天无意间看到了vbs这小玩意,就突发奇想,自学了一下,倒弄出如下的小玩意,大牛勿喷!这个可用做撩妹神技也可以用于提醒自己!使用方法:复制程序到txt文本里面保存,然后改后缀为vbs,丢到C:\Pro ...
- 利用HTML5开发Android(3)---Android中的调试
通过JS代码输出log信息 Js代码 Js代码: console.log("Hello World"); Log信息: Console: Hello World http://ww ...
- 【转】BitmapFactory.Options
BitmapFactory.Options这个类的信息:http://developer.android.com/reference/android/graphics/BitmapFactory.Op ...
- VS2010开发环境最佳字体及配色[转]
从地址:http://www.dev-club.net/xiangxixinxi/42010072906150537/201103010518006.html 获取的,整理如下: 环境:VS2010字 ...
- 转载:rebar和erlang
使用rebar生成erlang release 并进行热代码升级 http://blog.sina.com.cn/s/blog_6530ad590100wmkn.html 使用rebar工具开发erl ...
- CSS实现未知高度图文混合垂直居中
(从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期 2014-06-26) CSS实现未知高度图文混合垂直居中,阅读CSS实现未知高度图文混合垂直居中. IE6,IE7,FF3测试通过 ...
- 以Outlook样式分组和排列数据项
转载:http://www.cnblogs.com/peterzb/archive/2009/05/29/1491781.html OutlookGrid:以Outlook样式分组和排列数据项 (这里 ...