-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoinsatcoder.cpp
More file actions
33 lines (28 loc) · 802 Bytes
/
coinsatcoder.cpp
File metadata and controls
33 lines (28 loc) · 802 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
double arr[n+1];
for(int i=1;i<=n;i++){
cin>>arr[i];
}
double dp[n+1][n+1],res=0;
memset(dp,0,sizeof(dp));
dp[1][0] = 1.0 - arr[1];
for(int i = 2; i <= n; ++i)
dp[i][0] = dp[i - 1][0] * (1.0 - arr[i]);
dp[1][1] = arr[1];
for(int i = 2; i <= n; ++i)
dp[i][i] = dp[i - 1][i - 1] * arr[i];
for(int i = 1; i <= n; ++i) {
for(int j = 1; j < i; ++j)
dp[i][j] = dp[i - 1][j] * (1.0 - arr[i]) + dp[i - 1][j - 1] * arr[i];
}
for(int i = n / 2 + 1; i <= n; ++i)
res += dp[n][i];
cout << fixed << setprecision(10) << res;
}