

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 100 点
問題文
N を正の奇数とします。
N 枚のコインがあります。 コインには 1, 2, \ldots, N と番号が振られています。 各 i (1 \leq i \leq N) について、コイン i を投げると、確率 p_i で表が出て、確率 1 - p_i で裏が出ます。
太郎君は N 枚のコインをすべて投げました。 このとき、表の個数が裏の個数を上回る確率を求めてください。
制約
- N は奇数である。
- 1 \leq N \leq 2999
- p_i は実数であり、小数第 2 位まで与えられる。
- 0 < p_i < 1
入力
入力は以下の形式で標準入力から与えられる。
N p_1 p_2 \ldots p_N
出力
表の個数が裏の個数を上回る確率を出力せよ。 絶対誤差が 10^{-9} 以下ならば正解となる。
入力例 1
3 0.30 0.60 0.80
出力例 1
0.612
表の個数が裏の個数を上回るような各ケースの確率を計算すると、次のようになります。
- (コイン 1, コイン 2, コイン 3) = (表, 表, 表) となる確率は、0.3 × 0.6 × 0.8 = 0.144 である。
- (コイン 1, コイン 2, コイン 3) = (裏, 表, 表) となる確率は、0.7 × 0.6 × 0.8 = 0.336 である。
- (コイン 1, コイン 2, コイン 3) = (表, 裏, 表) となる確率は、0.3 × 0.4 × 0.8 = 0.096 である。
- (コイン 1, コイン 2, コイン 3) = (表, 表, 裏) となる確率は、0.3 × 0.6 × 0.2 = 0.036 である。
よって、表の個数が裏の個数を上回る確率は、0.144 + 0.336 + 0.096 + 0.036 = 0.612 です。
入力例 2
1 0.50
出力例 2
0.5
例えば、0.500
, 0.500000001
, 0.499999999
などを出力しても正解となります。
入力例 3
5 0.42 0.01 0.42 0.99 0.42
出力例 3
0.3821815872
Score : 100 points
Problem Statement
Let N be a positive odd number.
There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i.
Taro has tossed all the N coins. Find the probability of having more heads than tails.
Constraints
- N is an odd number.
- 1 \leq N \leq 2999
- p_i is a real number and has two decimal places.
- 0 < p_i < 1
Input
Input is given from Standard Input in the following format:
N p_1 p_2 \ldots p_N
Output
Print the probability of having more heads than tails. The output is considered correct when the absolute error is not greater than 10^{-9}.
Sample Input 1
3 0.30 0.60 0.80
Sample Output 1
0.612
The probability of each case where we have more heads than tails is as follows:
- The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Head) is 0.3 × 0.6 × 0.8 = 0.144;
- The probability of having (Coin 1, Coin 2, Coin 3) = (Tail, Head, Head) is 0.7 × 0.6 × 0.8 = 0.336;
- The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Tail, Head) is 0.3 × 0.4 × 0.8 = 0.096;
- The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Tail) is 0.3 × 0.6 × 0.2 = 0.036.
Thus, the probability of having more heads than tails is 0.144 + 0.336 + 0.096 + 0.036 = 0.612.
Sample Input 2
1 0.50
Sample Output 2
0.5
Outputs such as 0.500
, 0.500000001
and 0.499999999
are also considered correct.
Sample Input 3
5 0.42 0.01 0.42 0.99 0.42
Sample Output 3
0.3821815872