传送门:>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 26. Remove Duplicates from Sorted Array (easy)

    Given a sorted array, remove the duplicates in-place such that each element appear only once and ret ...

  2. HDU - 1255 扫描线+离散化进阶

    这道题最开始我以为和HDU - 1542 那道题一样,只需要把cover次数改成2次即可,但是后面仔细一想,我们需要求的是覆盖次数大于等于2次的,这样的话,我们需要维护两个长度,HDU-1542 由于 ...

  3. amd,cmd规范

    AMD 和 CMD 的区别有哪些? AMD规范与CMD规范的区别 回顾:前端模块化和AMD.CMD规范(全) 浅析JS模块规范:AMD,CMD,CommonJS 理解AMD ,CMD,CommonJS ...

  4. java高精度学习笔记

    高精度基本用法 valueOf(parament)     将参数转换为指定的类型 add()   相加   subtract() 相减    multiply()  相乘    divide()  ...

  5. Baby Coins

    题意 描述 Baby 今天清点自己的百宝箱啦,箱子里有n 种硬币,硬币的面值分别是:val[1],val[2],...,val[n],每种面值的硬币都恰好有2 个. Baby 实在闲的太无聊了,他想从 ...

  6. Choosing The Commander CodeForces - 817E (01字典树+思维)

    As you might remember from the previous round, Vova is currently playing a strategic game known as R ...

  7. 使用faker去构造一个User-Agent

    faker可以仿造各种各样的信息,可以使用faker去构造一个User-Agent from faker import Factory f = Factory.create() 'User-Agent ...

  8. 三次握手复习TCP

    临近下班,突然想起三次握手的概念有点模糊. 大学时候的<计算机网络>是英语版的,那时候学习迷迷糊糊的.大概记得一个模型罢了. 幸好,大学基本所有的书都卖了,就是计算机网络没卖.待会回去看看 ...

  9. 【学习总结】Git学习-参考廖雪峰老师教程二-安装Git

    学习总结之Git学习-总 目录: 一.Git简介 二.安装Git 三.创建版本库 四.时光机穿梭 五.远程仓库 六.分支管理 七.标签管理 八.使用GitHub 九.使用码云 十.自定义Git 期末总 ...

  10. Cannot connect to database because the database client

    问题描述: arcgis server10.1  arcgis sde10出现下面问题 Cannot connect to  database because the database client ...