【CodeForces - 518D】Ilya and Escalator(概率dp,数学期望)

题干:

Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.

Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him.

Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds.

Your task is to help him solve this complicated task.

Input

The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point.

Output

Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6.

Examples

Input

1 0.50 1

Output

0.5

Input

1 0.50 4

Output

0.9375

Input

4 0.20 2

Output

0.4

题目大意:

n个人在排成一队在电梯面前,最前面的人每一秒钟会进行一次选择,有p的概率进电梯,有1-p的概率停在原地。每个人只有他前面的人都进电梯了,他才有可能进电梯。求t秒之后,进电梯人数的期望值。

解题报告:

  看得出来,还是对概率dp的理解不是很透彻,换句话说是对dp的理解不是很透彻。转移的时候别忘记乘以对应的概率。

  dp[i][j]代表i秒过后,电梯上有j个人的概率 。这样就可以由两个状态转移而来,但是注意这时候要注意这只是定义了某个状态发生的概率,转移的同时还要乘以转移的概率,这两个概率不是一个东西,所以不能直接叠加上来。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e3 + 5;
int n,t;
double p,dp[MAX][MAX];//i秒过后,电梯上有j个人的概率 
int main()
{cin>>n>>p>>t;dp[0][0]=1;for(int i = 1; i<=t; i++) {dp[i][0] = dp[i-1][0]*(1-p);for(int j = 1; j<=n; j++) {dp[i][j] = dp[i-1][j] * (j == n ? 1 : (1-p));dp[i][j] += dp[i-1][j-1] * p;}}double ans = 0;for(int i = 1; i<=n; i++) ans += dp[t][i]*i;printf("%.8f\n",ans);return 0 ;
}

注意状态的转移不能直接叠加上来,比如说这样:要么第i秒没有人上来,那么就是i-1秒上来了j个人的概率;要么就是上来了一个人,就要乘以对应的概率。

for(int i = 1; i<=t; i++) {dp[i][0] = dp[i-1][0]*(1-p);for(int j = 1; j<=n; j++) {dp[i][j] = dp[i-1][j];dp[i][j] += dp[i-1][j-1] * p;}}

甚至还写出了这种四不像:

//    for(int i = 1; i<=n; i++) {
//        for(int j = 1; j<=t; j++) {
//            dp[i][j] += dp[i][j-1];
//            dp[i][j] += (1-dp[i][j-1])*p; 
//        }
//    }

总结:

其实就BZOJ - 3036这个算 经过路径长度的期望 一样:

但是那代码就要这么写了:

using namespace std;
int n, t;
double p, dp[2005][2005];int main() {scanf("%d%lf%d", &n, &p, &t);dp[0][0] = 1;double ans = 0;for (int i = 0; i < t; ++i) {dp[i + 1][n] += dp[i][n];for (int j = 0; j < n; ++j) if (dp[i][j] > 1e-10) {dp[i + 1][j + 1] += dp[i][j] * p;dp[i + 1][j] += dp[i][j] * (1 - p);ans += dp[i][j] * p;}}printf("%.8f\n", ans);return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440020.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Apollo进阶课程 ② | 开源模块讲解(上)

目录 1&#xff09;无人驾驶车介绍 2&#xff09;高精地图 3&#xff09;定位 4&#xff09;感知 5&#xff09;轨迹规划 6&#xff09;控制 7&#xff09;云端 原文链接&#xff1a;Apollo进阶课程 ② | 开源模块讲解&#xff08;上&#xff09; Apollo自动驾驶进阶课…

由浅到深理解ROS(9)- 几个基本概念的理解 坐标系 包

1.坐标系 最常用的就是map&#xff0c;odom&#xff0c;base_link&#xff0c;base_laser坐标系&#xff0c;这也是开始接触gmapping的一些坐标系。 map:地图坐标系&#xff0c;顾名思义&#xff0c;一般设该坐标系为固定坐标系&#xff08;fixed frame&#xff09;&#xff…

计算机常用技巧

windows禁用自带键盘命令&#xff08;笔记本&#xff09; 禁用&#xff1a;sc config i8042prt start disabled 恢复&#xff1a;sc config i8042prt start auto锁屏 win l

【POJ - 1698】Alice's Chance(网络流最大流,建图)

题干&#xff1a; Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invite her to play the chief role in their new films. Unfortunately, all these companies will start mak…

由浅到深理解ROS URDF教程

创建自己的URDF文件 1.1创建树形结构文件 在这部分教程中要创建的将是下面的图形所描述的机器人的urdf文件 图片中这个机器人是一个树形结构的。让我们开始非常简单的创建这个树型结构的描述文件&#xff0c;不用担心维度等的问题。创建一个my_robot.urdf文件&#xff0c;内容如…

wireshark基本使用及介绍

Wireshark使用 注&#xff1a;本文中使用的wireshark是3.2.2版本 捕获过滤器表达式 下面是常用的捕获过滤器&#xff0c;wireshark中&#xff1a;捕获->捕获过滤器 除此外&#xff0c;还可以指明传输方向&#xff0c;如&#xff1a;src&#xff08;源方向&#xff09;, …

1.2)深度学习笔记------神经网络的编程基础

目录 1&#xff09;Binary Classification 2&#xff09;Logistic Regression 3&#xff09;Logistic Regression Cost Function 4&#xff09;Gradient Descent 5&#xff09;Logistic Regression Gradient Descent&#xff08;重点&#xff09; 6&#xff09;Gradient …

CS231n Convolutional Neural Networks for Visual Recognition------Python Tutorial

源链接为&#xff1a;http://cs231n.github.io/python-numpy-tutorial/。 这篇指导书是由Justin Johnson编写的。 在这门课程中我们将使用Python语言完成所有变成任务&#xff01;Python本身就是一种很棒的通用编程语言&#xff0c;但是在一些流行的库帮助下&#xff08;numpy&…

【HDU - 3081】Marriage Match II(网络流最大流,二分+网络流)

题干&#xff1a; Presumably, you all have known the question of stable marriage match. A girl will choose a boy; it is similar as the game of playing house we used to play when we are kids. What a happy time as so many friends playing together. And it is …

IP、TCP、UDP、HTTP头部信息

IP头部信息 ip报文段格式 版本&#xff1a; 占4位&#xff0c;表明IP协议实现的版本号&#xff0c;当前一般为IPv4&#xff0c;即0100。报头长度 &#xff1a; 占4位&#xff0c;因为头部长度不固定&#xff08;Option可选部分不固定&#xff09;&#xff0c;所以需要标识…

ROS技术点滴 —— MoveIt!中的运动学插件

MoveIt!是ROS中一个重要的集成化开发平台&#xff0c;由一系列移动操作的功能包组成&#xff0c;提供运动规划、操作控制、3D感知、运动学等功能模块&#xff0c;是ROS社区中使用度排名前三的功能包&#xff0c;目前已经支持众多机器人硬件平台。 MoveIt!中的众多功能都使用插件…

1)机器学习基石笔记Lecture1:The Learning Problem

网上关于机器学习的课程有很多&#xff0c;其中最著名的是吴恩达老师的课程&#xff0c;最近又发现了NTU林轩田老师的《机器学习基石》课程&#xff0c;这门课也很好。课程总共分为4部分&#xff0c;总共分为16节课&#xff0c;今天来记录第一节课。 When Can Machines Learn?…

MMS协议

MMS格式解析 简介&#xff1a; MMS是微软的私有流媒体协议。 它的最初目的是通过网络传输多媒体广播、视频、音轨、现场直播和一系列的实时或实况材料。 MMS建立在UDP或TCP传输&#xff0f;网络层上&#xff0c;是属于应用层的。使用TCP的MMS上URL是MMS://或者MMST://&#x…

【HDU - 6118】度度熊的交易计划(最小费用可行流,网络流费用流变形 )

题干&#xff1a; 度度熊参与了喵哈哈村的商业大会&#xff0c;但是这次商业大会遇到了一个难题&#xff1a; 喵哈哈村以及周围的村庄可以看做是一共由n个片区&#xff0c;m条公路组成的地区。 由于生产能力的区别&#xff0c;第i个片区能够花费a[i]元生产1个商品&#xff0…

老王说ros的tf库

ros的tf库 为了这个题目&#xff0c;我是拿出了挤沟的精神挤时间&#xff0c;是下了功夫的&#xff0c;线性代数、矩阵论复习了&#xff0c;惯性导航里的dcm、四元数也了解了&#xff0c;刚体力学也翻了&#xff0c;wiki里的欧拉角也读了&#xff0c;tf的tutorial、paper、sou…

Apollo进阶课程 ③ | 开源模块讲解(中)

目录 1&#xff09;ISO-26262概述 2&#xff09;ISO-26262认证流程 3&#xff09;ISO-26262优点与缺陷 原文链接&#xff1a;Apollo进阶课程 ③ | 开源模块讲解&#xff08;中&#xff09; Apollo自动驾驶进阶课程是由百度Apollo联合北京大学共同开设的课程&#xff0c;邀请…

python 问题集

打开文件是报&#xff1a;UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xe9 in position 0: unexpected end of data UnicodeDecodeError:“utf-8”编解码器无法解码位置0中的字节0xe9:unex 在open中加入encodingunicode_escape 如&#xff1a; with open(file_n…

【HDU - 6447】YJJ's Salesman(降维dp,树状数组优化dp)

题干&#xff1a; YJJ is a salesman who has traveled through western country. YJJ is always on journey. Either is he at the destination, or on the way to destination. One day, he is going to travel from city A to southeastern city B. Let us assume that A …

由浅到深理解ROS(5.1)- roslaunch 学习

oslaunch 用处&#xff1a;将多个rosnode 结合起来&#xff0c;一起运行。这样就不需要一个个的运行。 roslaunch格式 &#xff08;add_two.launch&#xff09; <launch> <arg name"a" default"1" /> <arg name"b&q…

CS231n Convolutional Neural Networks for Visual Recognition------Numpy Tutorial

源链接为&#xff1a;http://cs231n.github.io/python-numpy-tutorial/。 这篇指导书是由Justin Johnson编写的。 在这门课程中我们将使用Python语言完成所有变成任务&#xff01;Python本身就是一种很棒的通用编程语言&#xff0c;但是在一些流行的库帮助下&#xff08;numpy&…