[题解] [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秒期望多少人上电梯 解题思路 ...
随机推荐
- c# mvc权限系统
登陆界面可以用index1,现在这个是仿照这个写的 登陆后的界面.模板都是套的,数据那个easyui自己写的 后台直接三层架构,dapper连处理数据后面加了autofac demo地址:https: ...
- 服务端相关知识学习(六)Zookeeper client
Zookeeper的client是通过Zookeeper类提供的.前面曾经说过,Zookeeper给使用者提供的是一个类似操作系统的文件结构,只不过这个结构是分布式的.可以理解为一个分布式的文件系统. ...
- char 、 unsigned char 互相转化
1. 利用unsigned char (即uchar) 保存char 数据 ,直接赋值即可 unsigned char uc; char c=-33; uc= c; cout<<(int ...
- 反序列化报错回显、反弹shell
• 使用java.net.URLClassLoader类,远程加载自定义类(放在自己服务器上的jar包),可以自定义方法执行. • 在自定义类中,抛出异常,使其成功随着Jboss报错返回命令执行结果. ...
- 2.Struts2-Action
struts.xml文件中 action 标签中几个属性的作用 1.name:为action命名,输入url访问时,需要带上action的name,通过name知道访问哪个action(通过class ...
- 【死磕 Java 集合】— ConcurrentSkipListMap源码分析
转自:http://cmsblogs.com/?p=4773 [隐藏目录] 前情提要 简介 存储结构 源码分析 主要内部类 构造方法 添加元素 添加元素举例 删除元素 删除元素举例 查找元素 查找元素 ...
- Linux 链接脚本分析
作者:答疑助手lizuobin 原文: https://blog.csdn.net/lizuobin2/article/details/51779064 在前面学习的过程中,看代码时遇到 arch_i ...
- Thymeleaf初探
Thymeleaf是一款用于渲染XML/XHTML/HTML5内容的模板引擎.类似JSP,Velocity,FreeMaker等,它也可以轻易的与Spring MVC等Web框架进行集成作为Web应用 ...
- Tunnel Warfare HDU - 1540 (线段树处理连续区间问题)
During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...
- 清除LabVIEW中波形图表或波形图中的历史数据
清除LabVIEW中波形图表或波形图中的历史数据 方法一: 前面板中右键单击波形图表或波形图,选择数据操作>>清除图表或数据操作>>清除图形 方法二:(编程方法) 用于清除图表 ...