# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884243 |
2023-12-07T01:21:19 Z |
qrno |
Kronican (COCI16_kronican) |
C++17 |
|
670 ms |
4544 KB |
#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 |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
7 ms |
4544 KB |
Output is correct |
6 |
Correct |
14 ms |
4444 KB |
Output is correct |
7 |
Correct |
30 ms |
4444 KB |
Output is correct |
8 |
Correct |
68 ms |
4444 KB |
Output is correct |
9 |
Correct |
659 ms |
4440 KB |
Output is correct |
10 |
Correct |
670 ms |
4520 KB |
Output is correct |