-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatDPI.cpp
More file actions
36 lines (30 loc) · 777 Bytes
/
Copy pathatDPI.cpp
File metadata and controls
36 lines (30 loc) · 777 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
34
35
36
/*
* Contest : AtCoder Educational DP Contest
* Problem : I - Coins
* Link : https://atcoder.jp/contests/dp/tasks/dp_i
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int main() {
fastio
int n; cin >> n;
vector<double> p(n);
for (int i = 0; i < n; ++i) cin >> p[i];
vector<double> dp(n + 1); // prob de i heads
dp[0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j >= 0; --j) {
dp[j] = dp[j] * (1 - p[i]);
if (j) dp[j] += dp[j - 1] * p[i];
}
}
double ans = 0;
for (int heads = 0; heads <= n; ++heads) {
int tails = n - heads;
if (heads > tails) ans += dp[heads];
}
cout << fixed << setprecision(10) << ans << '\n';
return 0;
}