Submission #98535

#TimeUsernameProblemLanguageResultExecution timeMemory
98535dalgerokKronican (COCI16_kronican)C++17
100 / 100
749 ms4600 KiB
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n, m; cin >> n >> m; int a[n][n]; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ cin >> a[i][j]; } } int dp[(1 << n)]; memset(dp, 63, sizeof(dp)); dp[(1 << n) - 1] = 0; for(int i = (1 << n) - 1; i >= 0; i--){ for(int j = 0; j < n; j++){ if((i >> j) & 1){ for(int k = 0; k < n; k++){ if(j == k){ continue; } if((i >> k) & 1){ dp[i ^ (1 << j)] = min(dp[i ^ (1 << j)], dp[i] + a[j][k]); } } } } } int ans = 2e9; for(int i = 0; i < (1 << n); i++){ if(__builtin_popcount(i) <= m){ ans = min(ans, dp[i]); } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...