Submission #98480

#TimeUsernameProblemLanguageResultExecution timeMemory
98480pamajKronican (COCI16_kronican)C++14
90 / 100
2019 ms4496 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 20; #pragma GCC optimize("Ofast") int n, k; int c[maxn][maxn]; int dp[1 << 20]; int solve(int mask) { if(__builtin_popcount(mask) >= n - k) return 0; if(dp[mask] != -1) return dp[mask]; int ans = 1e9; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(i == j or (mask & (1 << i)) or (mask & (1 << j))) continue; ans = min(ans, solve(mask | (1 << i)) + c[i][j]); } } return dp[mask] = ans; } int32_t main() { cin >> n >> k; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) cin >> c[i][j]; } memset(dp, -1, sizeof(dp)); cout << solve(0) << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...