Codeforces 518 D Ilya and Escalator
Discription
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, number p 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.
Examples
1 0.50 1
0.5
1 0.50 4
0.9375
4 0.20 2
0.4 设f[i][j]为过了T秒后电梯上有j个人的概率,直接转移就行了
#include<bits/stdc++.h>
#define ll long long
#define D double
using namespace std;
const int maxn=2005;
D P,ans=0,f[maxn][maxn];
int N,T; inline void dp(){
f[0][0]=1;
for(int i=0;i<T;i++){
for(int j=0;j<N;j++) if(f[i][j]>0){
f[i+1][j+1]+=f[i][j]*P;
f[i+1][j]+=f[i][j]*(1-P);
}
f[i+1][N]+=f[i][N];
}
} inline void calc(){
for(int i=1;i<=N;i++) ans+=f[T][i]*i;
} int main(){
cin>>N>>P>>T;
dp(),calc();
printf("%.11lf\n",ans);
return 0;
}
Codeforces 518 D Ilya and Escalator的更多相关文章
- 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 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 ...
- 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 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个人在电梯上,之后期望能有多 ...
- 【55.70%】【codeforces 557A】Ilya and Diplomas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 754B】 Ilya and tic-tac-toe game
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces#518 Div2 ABCDE
A---Birthday http://codeforces.com/contest/1068/problem/A 题意: 有n种硬币,m个人.m个人要给Ivan送硬币,每个人送的硬币都要互不相同但数 ...
随机推荐
- HTML5<picture>元素
HTML5<picture>元素可以设置多张图片 <!DOCTYPE html><html><head><meta http-equiv=&quo ...
- HTML网页的浏览器标题栏显示小图标的方法
HTML网页的浏览器标题栏显示小图标的方法 就像这种效果,方法其实很简单,就是 在head头部里写: <link rel='icon' href='pic.ico ' type='image ...
- vue建项目并使用
今天来回顾下vue项目的建立和使用,好久不用感觉不会用了. 下面两个都要全局安装 首先安装git,地址 https://gitforwindows.org/ 安装node, 地址 https://n ...
- vue-cli3.0 生产包去除console.log
目前负责的公众号又迭代了一个版本,之前打生产包,配置总是和测试包搞混,所以使用了vue-cli3.0的环境变量来控制配置. 但是又发现了一个新问题,写代码的过程中写了很多console.log 来调试 ...
- 【Java_基础】空串、空格串、null的区别
1.表示的区别 string str1 = ""; //空串 str1.length() 等于 0 string str2 = " "; / ...
- 三:MySql数据库及连接
前言: 开发中团队使用一个MYSQL数据库,我们只需要知道怎么去连接这个已经存在的数据库即可,因此关于MYSQL数据库安装部分可以去Baidu,并不是主要关心的部分 学会在windows7下使用DOS ...
- Beautiful Soup 4.2.0 doc_tag、Name、Attributes、多值属性
找到了bs4的中文文档,对昨天爬虫程序里所涉及的bs4库进行学习.这篇代码涉及到tag.Name.Attributes以及多值属性. ''' 对象的种类 Beautiful Soup将复杂HTML文档 ...
- 第一章 pyhton基础
一 .pyhton2与python3的区别 在pyhton2中,其中编码默认使用的是ascii编码,输出格式为print"xxx",输入为raw_input(“请输入”),在整型中 ...
- 不同深度的图片转换cvConvertScale
不同深度图像的转换:要注意范围比如IPL_DEPTH_8U 转到 IPL_DEPTH_32U要用cvConvertScale(pImg8, pImg32, 1.0/255, 0); 要除255反过来I ...
- tabel使用总结
对日常使用到的tabel做下记录: <table cellspacing="0"><!--单元格间距为零 默认为2 border默认为 0--> <t ...