-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc.cpp
More file actions
32 lines (29 loc) · 686 Bytes
/
Copy pathc.cpp
File metadata and controls
32 lines (29 loc) · 686 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
#include <bits/stdc++.h>
using namespace std;
int mark[16];
double p[16][16];
vector <int> ord;
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
double ans = 0.0, prod = 1.0;
cin >> n;
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
cin >> p[i][j];
for(int i = 0; i < n; ++i) ord.push_back(i);
while(1){
prod = 1.0;
memset(mark, 0, sizeof mark);
for(int i = 0; i < n; ++i){
mark[ord[i]] = 1;
for(int j = 0; j < n; ++j)
if(!mark[j]) prod *= p[ord[i]][j];
}
ans += prod;
if(!next_permutation(ord.begin(), ord.end())) break;
}
cout << fixed << setprecision(15) << ans << "\n";
return 0;
}