QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100

#9966. 跳高

Statistics

Henry 正在参加一场跳高比赛。在每次跳跃前,他可以选择一个从 $1$ 到 $n$ 的整数作为横杆高度。作为他的长期教练,你非常了解 Henry 的能力。对于每个可能的高度 $h$,你知道他成功跳过该高度的概率 $p_h$。显而易见,高度越高,成功的概率越低。

在今天的比赛中,不允许出现任何失误。一旦跳跃失败,比赛即告结束,选手的成绩为此前成功跳过的最高高度(如果第一次跳跃就失败,则成绩为 $0$)。如果成功跳过高度 $n$,比赛也会自动结束,成绩为 $n$。请帮助 Henry 为每次跳跃选择最优的高度,以使他得分的期望值*最大。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 500\,000$),表示横杆高度的上限。

第二行包含 $n$ 个实数 $p_1, p_2, \dots, p_n$ ($0 < p_i < 1; p_i > p_{i+1}$),每个数小数点后最多有 $9$ 位。其中 $p_i$ 表示成功跳过高度 $i$ 的概率。

输出格式

输出一个实数,表示 Henry 得分的最大期望值。

你的答案需要满足绝对误差或相对误差不超过 $10^{-6}$。也就是说,如果你输出 $x$,而正确答案为 $y$,那么当 $|x - y| \le 10^{-6} \cdot \max(1, y)$ 时,你的答案将被视为正确。你最多可以在小数点后输出 $20$ 位。

样例

输入 1

5
0.9 0.85 0.6 0.456000 0.000000017

输出 1

2.475200006589

说明

以下策略是最优的:

  • 将横杆高度设为 $2$。Henry 以 $0.85$ 的概率跳过,或以 $0$ 分结束(概率为 $0.15$)。
  • 如果他跳过了第一次跳跃,将横杆高度设为 $4$。Henry 以 $0.456$ 的概率跳过,或以 $2$ 分结束。
  • 如果他跳过了第二次跳跃,将横杆高度设为 $5$。Henry 以 $0.000000017$ 的概率跳过并以 $5$ 分结束,或失败并以 $4$ 分结束。

该策略的期望值为: $0 \cdot 0.15 + 2 \cdot 0.85 \cdot 0.544 + 4 \cdot 0.85 \cdot 0.456 \cdot 0.999999983 + 5 \cdot 0.85 \cdot 0.456 \cdot 0.000000017 = 2.4752000065892$

*期望值是随机变量的概率加权平均值。直观地说,它是如果重复进行多次随机实验,实验结果的平均值。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.