QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#7497. 葫芦娃救爷爷

Statistics

有 $n$ 个葫芦娃,第 $i$ 个葫芦娃的战斗力是 $p_i$,在第 $i$ 天早上出生。保证所有 $p_i$ 的总和是 $1$。

第 $i$ 天晚上,已经出生的葫芦娃可以选择积攒实力(等明天)或者所有人出发去救爷爷,如果这些葫芦娃的实力总和为 $P$,那么有 $P$ 的概率救出爷爷,$1-P$ 的概率失败,如果失败了,那么这轮参与援救的葫芦娃都会被妖精抓走,之后无法参与救援。

但是,妖精用俄罗斯轮盘的方式决定爷爷的生死。也就是说,妖精会首先随机在 $1$ 到 $n$ 里均匀生成一个正整数 $x$,然后在第 $x$ 天中午杀死爷爷。如果爷爷已经被杀死了,那么葫芦娃的救援活动自然失败。葫芦娃无法知道 $x$

请你帮忙计算,葫芦娃应该按照什么策略展开救援,最大化爷爷获救的概率。

输入格式

第一行输入一个正整数 $n$。

接下来一行输入 $n$ 个小数 $p_i$。

输出格式

输出一个小数,表示最优策略下爷爷获救的概率。你的答案只要误差不超过 $10^{-6}$ 就算对。

样例数据

样例 1 输入

1
1

样例 1 输出

0

样例 2 输入

7
0.5 0.5 0 0 0 0 0

样例 2 输出

0.71428571428571430157

样例 2 解释

最优解是第二天两个人一起救,此时如果爷爷还没死那么营救一定成功。

成功营救的概率就是 $5/7$。

样例 3 输入

7
0.537354 0.277078 0.124580 0.046589 0.012498 0.001853 0.000048

样例 3 输出

0.59878460205905026381

数据范围

对于 $30\%$ 的数据,保证 $n\leq 3$。

对于 $60\%$ 的数据,保证 $n\leq 15$。

对于 $100\%$ 的数据,保证 $n\leq 1000$。

保证输入的 $\sum p_i =1$,小数点不超过 $6$ 位。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.