-
Notifications
You must be signed in to change notification settings - Fork 2
/
i.cpp
49 lines (37 loc) · 747 Bytes
/
i.cpp
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;
double arr[3005];
double dp[3005][3005];
int n;
double kil(int idx, int heads)
{
if(idx == n)
{
if(heads > n - heads)
return 1;
return 0;
}
if(dp[idx][heads] != -1)
return dp[idx][heads];
dp[idx][heads] = 0;
dp[idx][heads] += arr[idx] * kil(idx+1, heads+1);
dp[idx][heads] += (1-arr[idx]) * kil(idx+1, heads);
return dp[idx][heads];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(int i=0;i<n;i++)
cin>>arr[i];
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
dp[i][j] = -1;
cout<<setprecision(10);
cout<<kil(0, 0)<<endl;
return 0;
}