forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ.cpp
More file actions
43 lines (37 loc) · 977 Bytes
/
J.cpp
File metadata and controls
43 lines (37 loc) · 977 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
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("way.in", "r", stdin);
freopen("way.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
double prob[22][22], probA[22], probB[22];
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> probA[i];
for (int i = 0; i < m; i++)
cin >> probB[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> prob[i][j];
double ans = 1;
for (int mask = 0; mask < 1 << n; mask++)
{
double curProb = 1;
for (int i = 0; i < n; i++)
if (mask >> i & 1) curProb *= probA[i];
else curProb *= 1 - probA[i];
for (int j = 0; j < m; j++)
{
double probLeft = 1;
for (int i = 0; i < n; i++)
if (mask >> i & 1)
probLeft *= 1 - prob[i][j];
curProb *= 1 - (1 - probLeft) * probB[j];
}
ans -= curProb;
}
cout << fixed << setprecision(9) << ans << endl;
}