Submission #88456

#TimeUsernameProblemLanguageResultExecution timeMemory
88456xiaowuc1Kronican (COCI16_kronican)C++14
100 / 100
816 ms4820 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> edge; int w[20][20]; int dp[1<<20]; void solve() { int n, k; cin >> n >> k; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { cin >> w[i][j]; } } int ret = 1 << 30; for(int mask = 0; mask < (1<<n); mask++) { dp[mask] = 1 << 30; } dp[(1<<n)-1] = 0; for(int mask = (1<<n)-1; mask >= 0; mask--) { int bits = __builtin_popcount(mask); if(bits == k) { ret = min(ret, dp[mask]); } if(bits <= k) continue; for(int i = 0; i < n; i++) { if(!(mask&(1<<i))) continue; for(int j = 0; j < n; j++) { if(i!=j && (mask&(1<<j))) { dp[mask^(1<<i)] = min(dp[mask^(1<<i)], dp[mask] + w[i][j]); } } } } cout << ret << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...