Problem:
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

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define MAX 1000000
#define mo 1000000007 
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

bool prime[MAX + 1]; 
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
  
    prime[1] = false; 
  
    for (int p = 2; p * p <= MAX; p++) { 
  
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) { 
  
            // Set all multiples of p to non-prime 
            for (int i = p * 2; i <= MAX; i += p) 
                prime[i] = false; 
        } 
    } 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll modexp(ll x, ll y, ll p)
{
ll res = 1;   
x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
} 
// Function to return LCM of two numbers  
  ll lcm(ll a, ll b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
ll mypow(ll b, ll e) {
    ll ans=1; for(;e;b=b*b%mo,e/=2) if(e&1) ans=ans*b%mo; return ans;}
ll power2(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power2(x, y / 2) * power2(x, y / 2); 
    else
        return x * power2(x, y / 2) * power2(x, y / 2); 
} 
ll mod=100000000;
#define MAXN 100001
ll spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}
ll bin(ll n, ll k)  
{  
    // Base Cases  
    if (k == 0 || k == n)  
        return 1;  
  
    // Recur  
    return bin(n - 1, k - 1) +  
                bin(n - 1, k);  
}  
ld dp[3001][3001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ld p[n+1];
	for(ll i=1;i<=n;i++)
	cin>>p[i];
	dp[0][0]=1;
	for(ll i=1;i<=n;i++)
	dp[0][i]=dp[0][i-1]*(1-p[i]);
	for(ll i=1;i<=n;i++)
	dp[i][i]=dp[i-1][i-1]*p[i];
	for(ll i=1;i<=n;i++)
	{
		for(ll j=i;j<=n;j++)
		{
			if(i==j)
			continue;
			dp[i][j]=dp[i-1][j-1]*p[j]+dp[i][j-1]*(1-p[j]);
		}
	}
	ll k=n/2+1;
	ld ans=0;
	for(ll i=k;i<=n;i++)
	ans+=dp[i][n];
 	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}