传送门:>Here<

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

解题思路:

  期望DP。

  $f[i][j]$表示第i秒上了j个人的概率。

  $f[1][1] = p, f[1][0] = (1 - p)$,并且$f[i][0]$都需要初始化。($* (1 - p)$)

  这题好像和普通的期望DP不太一样啊,因为f数组设的是概率而不是期望。这样设的话答案就应该是$\sum\limits_{i = 0}^{Min(n, t)}f[t][i] * i$

  考虑如何转移:

  第i秒的时候不上人:$ f[i-1][j] * (1 - p) $

  第i秒的时候上人:$ f[i-1][j-1] * p $

  因此对于一般情况:$$f[i][j] = f[i-1][j] * (1 - p) + f[i-1][j-1] * p$$

  另外,总共就n个人,如果$t > n$就需要特判了:$$f[i][n] = f[i-1][n] + f[i-1][n-1]*p$$

Code

  还是边界条件!对于$f[i][j]$,由于每秒最多上一个人,所以$j$是不可能大于$i$的,要特判一下。

/*By QiXingzhi*/
#include <cstdio>
#include <queue>
#define r read()
#define Max(a,b) (((a)>(b)) ? (a) : (b))
#define Min(a,b) (((a)<(b)) ? (a) : (b))
using namespace std;
typedef long long ll;
const int N = ;
const int INF = ;
inline int read(){
int x = ; int w = ; register int c = getchar();
while(c ^ '-' && (c < '' || c > '')) c = getchar();
if(c == '-') w = -, c = getchar();
while(c >= '' && c <= '') x = (x << ) +(x << ) + c - '', c = getchar();
return x * w;
}
int n,t;
double p,f[N][N],cur,ans;
int main(){
// freopen(".in", "r", stdin);
scanf("%d %lf %d",&n,&p,&t);
f[][] = p;
f[][] = -p;
for(int i = ; i <= t; ++i){
f[i][] = f[i-][] * (-p);
}
for(int i = ; i <= t; ++i){
for(int j = ; j <= n; ++j){
if(j > i){
break;
}
f[i][j] = f[i-][j]*(-p) + f[i-][j-]*p;
}
f[i][n] = f[i-][n] + f[i-][n-] * p;
}
for(int i = ; i <= n; ++i){
if(i > t) break;
ans += f[t][i] * i;
}
printf("%.8lf", ans);
return ;
}

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

  1. D. Ilya and Escalator

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

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

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

  3. 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 ...

  4. 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 ...

  5. Codeforces 518 D Ilya and Escalator

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

  6. Codeforces 518D Ilya and Escalator

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

  7. ●CodeForces 518D Ilya and Escalator

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

  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. Mac 下编译安装 php-5.6

    1.安装 PHP 1.1 下载源码包 http://php.net/get/php-5.6.35.tar.bz2/from/a/mirror 1.2 编译&安装 ./configure --p ...

  2. 海康威视笔试(C++)

    1. select和epoll的区别 2.服务器并发量之高性能服务器设计 3.SQL关键字 4.TCP乱序和重传的问题 5.c++对象内存分配问题 6.c++多线程 join的用法: Thread类的 ...

  3. Django model操作

    一.各种查询统计操作   def all(self) # 获取所有的数据对象 def filter(self, *args, **kwargs) # 条件查询 # 条件可以是:参数,字典,Q def ...

  4. React不同版本之间需要注意的地方

    React Fiber react fiber指的是react16.0机器之后的版本,相对于之前的版本来说,这一个版本的更新做了很多的优化,所以和之前的版本中的用法可能会发生不同,所以,平常开发中,主 ...

  5. semantic-ui 分段

    分段:用于创建一组相关联的内容. 1.创建一个基础的分段 在class中加一个segment的class即可 <div class="ui segment"> < ...

  6. 【学习总结】C-翁恺老师-入门-第0周<程序设计与C>

    [学习总结]C-翁恺老师-入门-总 1-首先按视频说的下载编辑器 <DevC++> 并一路默认设置: 安装包下载链接 (我有vc6.0不过预感告诉我老师要用类似CS50里那种命令行编辑器? ...

  7. python Drools

    python Drools - 国际版 Binghttps://cn.bing.com/search?q=python+Drools&qs=n&FORM=BESBTB&sp=- ...

  8. Jenkins [Error] at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:192)

    Deploying /root/.jenkins/workspace/zgg-crm-pre/target/crm.war to container Tomcat 7.x Remote with co ...

  9. java对象的四种引用:强引用、软引用、弱引用和虚引用

    在JDK1.2之前,创建的对象只有在处于可触及(reachable)的状态下,才能被程序使用.也就是说,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.垃圾回收器一旦发现这些无用对象,就会对 ...

  10. [转帖]国产闪存颗粒终于熬出头 紫光存储S100固态硬盘评测

    国产闪存颗粒终于熬出头 紫光存储S100固态硬盘评测 https://www.cnbeta.com/articles/tech/830875.htm 全国产的 SSD 群联貌似是对岸的 不过不管怎么说 ...