[题解] [CF518D] Ilya and Escalator
题面
题解
期望dp入门题
设\(f[i][j]\)为到\(i\)时间有\(j\)个人上了电梯的概率, 我们可以得到转移方程
\]
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的更多相关文章
- CF518D. Ilya and Escalator [概率DP]
CF518D. Ilya and Escalator 题意:n个人,每秒p的概念队首的人进入电梯,求t秒后期望人数 直接使用期望定义 \(f[i][j]\) i秒后电梯中j个人的概率 注意n个人的时候 ...
- 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 ...
- 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 518 D Ilya and Escalator
Discription Ilya got tired of sports programming, left university and got a job in the subway. He wa ...
- ●CodeForces 518D Ilya and Escalator
题链: http://codeforces.com/problemset/problem/518/D题解: 期望dp. 定义dp[t][i]表示在第t秒开始之前,已经有了i个人在电梯上,之后期望能有多 ...
- 【Henu ACM Round#15 D】Ilya and Escalator
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 概率DP; 设f[i][j]表示前i个单位时间,j个人进入房间的概率是多少 然后想一下和i-1秒的时候要怎么转移就可以了. i-1秒 ...
- Codeforces 518D Ilya and Escalator
http://codeforces.com/problemset/problem/518/D 题意:n个人,每秒有p的概率进电梯,求t秒后电梯里人数的期望 考虑dp:f[i][j]代表第i秒有j个人的 ...
- Codeforces518 D. Ilya and Escalator
传送门:>Here< 题意:有n个人排队做电梯,每个人必须等前面的人全部上了以后才能上.对于每秒钟,有p的概率选择上电梯,(1-p)的概率选择不上电梯.现在问t秒期望多少人上电梯 解题思路 ...
随机推荐
- curl 的使用
curl 的使用 作者:与蟒唯舞链接:https://www.jianshu.com/p/f05bbd5007d9 curl 是一种命令行工具,作用是发出网络请求,然后获取数据,显示在"标准 ...
- O043、计算节点宕机了怎么办
参考https://www.cnblogs.com/CloudMan6/p/5562131.html Rebuild 可以恢复损坏的instance .那如果是宿主机坏了怎么办呢?比如硬件故障或者 ...
- O038、Shelve Instance 操作详解
参考https://www.cnblogs.com/CloudMan6/p/5524751.html Instance 被 Suspend 后虽然处于 shutdown 状态,但 Hypervis ...
- python版本
一般在Linux下,默认会安装一个python2.*的版本,但是我们自己开发有时候需要python3.*的版本 1. 安装python3 .安装依赖包 )首先安装gcc编译器,gcc有些系统版本已经默 ...
- js安全类型检测
背景: 都知道js内置的类型检测,大多数情况下是不太可靠的,例如: typeof . instanceof typeof 返回一个未经计算的操作数的类型, 可以发现所有对象都是返回object ...
- 7 java 笔记
1 方法是类或者对象行为特征的抽象,方法是类或对象最重要的组成部分 2 java里面方法的参数传递方式只有一种:值传递 值传递:就是将实际参数值的复制品传入方法内,而参数本身不会受到任何影响.(这是j ...
- 3.移动端自动化测试-appium环境搭建(原理)
appium自动化原理: 需要服务端(appium启动),手机端(adb连接设备),脚本端(pycharm)就可以进行 自己总结下: 手机和脚本连接:1.adb连接,2靠脚本导入驱动. 脚本和服务端连 ...
- Flask框架学习篇(一)
安装好Python,pip install flask安装好flask后,开始编写第一个flask程序 #包含动态路由的flask程序from flask import Flask app= Flas ...
- JVM学习笔记(一,待整理)
1. 2. 3. 4.-Xint.-Xcomp.-Xmixed 在解释模式(interpreted mode)下,-Xint标记会强制JVM执行所有的字节码,当然这会降低运行速度,通常低10倍或更多. ...
- three.js之创建一条直线
<!DOCTYPE html> <html> <head> <meta charset=utf-8> <title>My first thr ...