QOJ.ac

QOJ

时间限制: 1 s 内存限制: 128 MB 总分: 100

#7497. 葫芦娃救爷爷

统计

$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

出力

0

入出力例 2

入力

7
0.5 0.5 0 0 0 0 0

出力

0.71428571428571430157

注記 2

最適解は2日目に2人で救出に向かうことであり、このとき祖父がまだ生きていれば救出は必ず成功します。

救出成功の確率は $5/7$ となります。

入出力例 3

入力

7
0.537354 0.277078 0.124580 0.046589 0.012498 0.001853 0.000048

出力

0.59878460205905026381

制約

$30\%$ のデータについて、$n \leq 3$ を満たす。

$60\%$ のデータについて、$n \leq 15$ を満たす。

$100\%$ のデータについて、$n \leq 1000$ を満たす。

入力される $\sum p_i = 1$ であり、小数点以下の桁数は $6$ 桁以内である。

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.