题面

题解

期望dp入门题

设\(f[i][j]\)为到\(i\)时间有\(j\)个人上了电梯的概率, 我们可以得到转移方程

\[f[i][j]=\begin{cases}f[i-1][j]\cdot(1-p),&j=0\\f[i-1][j-1]\cdot p+f[i-1][j]\cdot(1-p),&j\in[1,n)\\f[i-1][n]+f[i-1][n-1]\cdot p,&j=n\end{cases}
\]

Code

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#define itn int
#define reaD read
#define N 2005
using namespace std; int n, t;
double f[N][N], p, ans; inline int read()
{
int x = 0, w = 1; char c = getchar();
while(c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); }
while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
return x * w;
} int main()
{
n = read(); scanf("%lf", &p); t = read();
f[0][0] = 1;
for(int i = 1; i <= t; i++)
{
f[i][0] = f[i - 1][0] * (1 - p);
for(int j = 1; j < n; j++) f[i][j] = f[i - 1][j - 1] * p + f[i - 1][j] * (1 - p);
f[i][n] = f[i - 1][n] + f[i - 1][n - 1] * p;
}
for(int i = 1; i <= n; i++) ans = (ans + (double) f[t][i] * i);
printf("%lf\n", ans);
return 0;
}

[题解] [CF518D] Ilya and Escalator的更多相关文章

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

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

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

  3. D. Ilya and Escalator

    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题解: 期望dp. 定义dp[t][i]表示在第t秒开始之前,已经有了i个人在电梯上,之后期望能有多 ...

  7. 【Henu ACM Round#15 D】Ilya and Escalator

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 概率DP; 设f[i][j]表示前i个单位时间,j个人进入房间的概率是多少 然后想一下和i-1秒的时候要怎么转移就可以了. i-1秒 ...

  8. Codeforces 518D Ilya and Escalator

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

  9. Codeforces518 D. Ilya and Escalator

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

随机推荐

  1. java基础4(线程)

    1.请简单描述什么是并行,什么是并发? 并行:指两个或多个事件在同一时刻发生(同时发生). 并发:指两个或多个事件在同一个时间段内发生. 通俗易懂版: 你吃饭吃到一半,电话来了,你一直到吃完了以后才去 ...

  2. 如何使用koa搭建一个简单服务

    1.首先检测是否已经有node环境?   把Windows的黑窗体的命令行工具调用出来   敲击命令行node -v , 然后,就可以看到这个打印出了一个版本号,这就证明我们的node.js已经是安装 ...

  3. css基础(代码)

    display: block; /*元素分为三大类,设置元素的显示方式}                                         行内 inlineli{            ...

  4. C# 斐波那契数列 第n项数字/前n项的和

    static void Main(string[] args) { int a = Convert.ToInt32(Console.ReadLine()); //求第n位数字是多少 Console.W ...

  5. 5.Hibernate 核心开发接口

    一.Configuration(AnnotationConfiguration) 作用:进行配置信息的管理 目标:用来产生SessionFactory 可以在configure 方法中指定hibern ...

  6. springboot搭建web项目与使用配置文件

    目录 一.准备工作 二.创建基础web项目 1. maven配置 2.创建maven项目.配置pom.xml为web基础项目 3.编写启动类 4.使用maven打包 5.使用命令java -jar x ...

  7. IoT 设备通信安全讨论

    IoT 设备通信安全讨论 作者:360CERT 0x00 序言 IoT 设备日益增多的今天,以及智能家居这一话题愈发火热,智能家居市场正在飞速的壮大和发展,无数 IoT 设备正在从影片中不断的走向用户 ...

  8. Percona MongoDB 4 搭建副本集

    什么是副本集: 是一组维护相同数据集的mongod进程 提供冗余,自动故障转移和高可用性 提供读取可伸缩性 内部概念或多或少与MySQL的概念相似 PRIMARY概念与MySQL复制中的MASTER大 ...

  9. 卸载CUDA和cuDNN

    卸载CUDA和cuDNN 1.卸载CUDA 本教程只针对对于.run方式安装的,其他的没有进行测试 打开终端,输入sudo /usr/local/cuda-10.0/bin/uninstall_cud ...

  10. Java语言基础(8)

    1 数组(二) 1)for-each循环:增强的for循环,JDK1.5推出的,用来输出数组和集合中每一个元素的值. for(数据类型 变量 : 数组名){ 变量:临时保存元素的值 } 数据类型必须跟 ...