제출 #98493

#제출 시각아이디문제언어결과실행 시간메모리
98493pamajKronican (COCI16_kronican)C++14
100 / 100
1358 ms4600 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]; int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); cin >> n >> k; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) cin >> c[i][j]; } for(int mask = 0; mask < (1 << n); mask++) { if(__builtin_popcount(mask) <= k) {dp[mask] = 0; continue;} int ans = 1e7; 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, dp[mask ^ (1 << i)] + c[i][j]); } } dp[mask] = ans; } cout << dp[(1 << n) - 1] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...