coins

mail@pastecode.io avatar
unknown
c_cpp
a year ago
635 B
3
Indexable
Never
#include <bits/stdc++.h>
using namespace std ;
const int maxn = 3007 ;
double dp[maxn][maxn] ;
double p[maxn] ;
int main (){
 int a;
 double ans = 0 ;
 cin >> a;
 for(int i = 1 ; i <= a ;i++){
    cin >> p[i] ;
 }
 dp[0][0] = 1 ;
 for(int i = 1 ; i <= a ; i++){
    for(int j = 0 ; j <= a ; j++){
      if (j == 0)
         dp[i][j] = dp[i-1][j]*(1-p[i]) ;
      else if (i == j) dp[i][j] = dp[i-1][j-1]*(p[i]) ;
      else if (i > j)
        dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*(p[i]); 
    }
 } 
   for(int j = a/2 +1 ; j <= a ; j++)
         ans += dp[a][j] ;
    
 cout << ans ;
    return 0;
}