-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathU - Grouping.cpp
More file actions
32 lines (27 loc) · 766 Bytes
/
Copy pathU - Grouping.cpp
File metadata and controls
32 lines (27 loc) · 766 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;
#define int long long
#define endl '\n'
const int mxN = 1 << 17;
int dp[mxN];
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
int G[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> G[i][j];
for (int mask = 1; mask < 1 << n; mask++) {
for (int j = 0; j < n; j++) if (mask >> j & 1) {
for (int i = j + 1; i < n; i++) if (mask >> i & 1) {
dp[mask] += G[i][j];
}
}
}
for (int mask = 1; mask < 1 << n; mask++) {
for (int s = mask; s > 0; s = (s - 1) & mask) {
dp[mask] = max(dp[mask], dp[s] + dp[mask ^ s]);
}
}
cout << dp[(1 << n) - 1];
}