Submission #884243

#TimeUsernameProblemLanguageResultExecution timeMemory
884243qrnoKronican (COCI16_kronican)C++17
100 / 100
670 ms4544 KiB
#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 timeMemoryGrader output
Fetching results...