Submission #165926

#TimeUsernameProblemLanguageResultExecution timeMemory
165926_qVp_Kronican (COCI16_kronican)C++14
100 / 100
956 ms4600 KiB
#include <bits/stdc++.h> using namespace std; const int md = 2e7 + 10; const int oo = 1e9 + 10; int f[md]; int n, k, c[30][30]; int getbit(int x, int i) { return ((x >> i) & 1); } //1010011 //0010000 int offbit(int x, int i) { return ((1 << i) ^ x); } int main() { // freopen("test.in", "r", stdin); //freopen("test.out", "w", stdout); ios_base::sync_with_stdio(0); cin >> n >> k; if (k >= n) { cout << "0"; return 0; } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) cin >> c[i][j]; } int res = oo; int ss = (1 << n) - 1; for(int i = 1; i <= ss; i++) f[i] = oo; f[ss] = 0; for(int s = ss; s >= 1; s--) { for(int i = 0; i < n; i++) if (getbit(s, i)) { int now = offbit(s, i); for(int j = 0; j < n; j++) if (getbit(now, j)) f[now] = min(f[now], f[s] + c[i + 1][j + 1]); } } for(int i = 1; i <= ss; i++) { int cnt = 0; for(int j = 0; j < n; j++) cnt += getbit(i, j); if (cnt == k) res = min(res, f[i]); } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...