제출 #959586

#제출 시각아이디문제언어결과실행 시간메모리
959586Beerus13Kronican (COCI16_kronican)C++14
100 / 100
546 ms4568 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define bit(mask, i) ((mask >> i) & 1) const int N = 1 << 20; int n, k; int a[20][20], dp[N + 5]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) cin >> a[i][j]; memset(dp, 0x3f, sizeof(dp)); dp[(1 << n) - 1] = 0; for(int mask = (1 << n) - 1; mask; --mask) { for(int i = 0; i < n; ++i) if(bit(mask, i)) { for(int j = 0; j < n; ++j) if(!bit(mask, j)) { int pre = mask | (1 << j); dp[mask] = min(dp[mask], dp[pre] + a[j][i]); } } } int ans = 1e9; for(int mask = 0; mask < (1 << n); ++mask) { if(__builtin_popcount(mask) <= k) ans = min(ans, dp[mask]); } return cout << ans, 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...