# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
884243 | qrno | Kronican (COCI16_kronican) | C++17 | 670 ms | 4544 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 20;
int N, K;
int C[MAXN][MAXN];
int DP[1 << MAXN];
int main() {
memset(DP, 0x3f, sizeof(DP));
cin >> N >> K;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
cin >> C[i][j];
int ans = INF;
DP[(1 << N)-1] = 0;
for (int m = (1 << N)-1; m >= 0; m--) {
for (int i = 0; i < N; i++) {
if (!(m & (1 << i))) continue;
for (int j = 0; j < N; j++) {
if (!(m & (1 << j)) || (i == j)) continue;
DP[m^(1<<i)] = min(DP[m^(1<<i)], DP[m] + C[i][j]);
}
}
if (__builtin_popcount(m) <= K) {
ans = min(ans, DP[m]);
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |