-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoin.cpp
More file actions
89 lines (75 loc) · 2.22 KB
/
Coin.cpp
File metadata and controls
89 lines (75 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//BAAP IZ HERE//
/*
KABILAN . M
PRATICE IS THE ONLY SHORTCUT TO SUCCESS
IIT GUWAHATI
*/
#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
using namespace std;
#define ff first
#define ss second
#define sb substr
#define all(v) v.begin(),v.end()
#define ll long long int
#define ull unsigned long long int
#define pi pair <ll, ll>
#define ppi pair<ll,pair<ll,ll>>
#define db double
#define bits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define pb(x) push_back(x)
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<ll>
#define forl(i,n) for(ll i = 0; i < n; i++)
#define deb(x) cout << #x << "=" << x << endl
#define p0(a) cout << a << " "
#define p1(a) cout << a << ln
#define p2(a,b) cout << a << " " << b << ln
#define p3(a,b,c) cout << a << " " << b << " " << c << ln
#define p4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << ln
const int maxN = 1e5+5;
const int MOD = 1e9+7;
void solve() {
//cout<<"NEVER GIVE UP"<<ln;
ll n;
cin >> n;
vector<double> dp(n+1);
// dp[heads], tail = 1 - head;
// dp[i] .. prob. that there are i head so far.
dp[0] = 1; /* BASE CONDITION */
// prob of having 0 head is 1.
for(int coin=1;coin<=n;coin++){
double p_head;
cin >> p_head;
for(int i=coin;i>=0;i--){ // going upto "0" heads
dp[i] = (i == 0 ? 0 : dp[i-1]*p_head) // i-1 head from prev and consider current p_head
+ dp[i]*(1-p_head); // if i is tail then dp[i]*(1-p_head) --> prob of i head so far
}
}
double ans = 0;
for(int head=0;head<=n;head++){
int tail = n - head; // we want more head than tail prob
if(head > tail){
ans += dp[head];
}
}
cout<<prec(10)<<ans<<ln;
return;
}
int main(){
fast;
ll t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}