传送门:>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. Leetcode 686 Repeated String Match

    Given two strings A and B, find the minimum number of times A has to be repeated such that B is a su ...

  2. python的四种内置数据结构

    对于每种编程语言一般都会规定一些容器来保存某些数据,就像java的集合和数组一样python也同样有这样的结构 而对于python他有四个这样的内置容器来存储数据,他们都是python语言的一部分可以 ...

  3. MongoDB Redis

    MongoDB Redis设置用户名密码了吗?看看shodan这款邪恶的搜索引擎吧!~   早上看新闻的时候看到了个醒目的新闻 开源中国:MongoDB 赎金事件持续发酵,究竟是谁之过?博客园:Mon ...

  4. Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval o

    pom.xml报错: Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from https://repo.maven.apach ...

  5. winform自定义控件开发

    1.添加控件属性 //添加私有的控件属性 private string djm;//单据名 //添加属性描述 [Browsable(true)] [Description("djm" ...

  6. Oracle如何扩展表空间

    一: --查看表空间的名字及文件所在位置 select tablespace_name, file_id, file_name, ), ) total_space from sys.dba_data_ ...

  7. asp.net core前后端分离

    陆陆续续的看了两个礼拜的前端知识,把vue+vue-router+axios的知识撸了一遍,本来想加个element-ui来实现一下前后端分离,实施的时候却遇到了很多的坑.我本身不在一个软件开发公司上 ...

  8. Oracle 序列(sequence)

    序列(sequence) 是Oracle提供的用于生成一系列唯一数字的数据库对象.它会自动生成顺序递增或者递减的序列号,以实现自动提供唯一的主键值.序列可以在多用户并发环境中使用,并且可以为所有用户生 ...

  9. Linux 下面 Sqlserver 2017 的简单安装

    1. 公司网络太烂 yum 在线安装失败 2. 解决方法 找微软的官网 百度网盘 离线下载rpm包. https://packages.microsoft.com/rhel/7/mssql-serve ...

  10. python raise

    当程序出现错误,python会自动引发异常,也可以通过raise显示地引发异常.一旦执行了raise语句,raise后面的语句将不能执行.   演示raise用法 try: s = None if s ...