Submission #81761

#TimeUsernameProblemLanguageResultExecution timeMemory
81761ngot23Kronican (COCI16_kronican)C++11
100 / 100
251 ms4748 KiB
#include<bits/stdc++.h> #define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i) #define Task "" using namespace std; const int N=21; int dp[1ll<<N], c[N][N], n, k, luu[N], dem; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen(Task".inp", "r", stdin); //freopen(Task".out", "w", stdout); cin >> n >> k; rep(i, 1, n) rep(j, 1, n) cin >> c[i][j]; rep(i, 0, (1ll<<n)-1) { if(__builtin_popcount(i)<=k) dp[i]=0; else dp[i]=1000000000; } rep(i, 0, (1ll<<n)-1) { int num=__builtin_popcount(i); if(num<=k) continue; dem=0; rep(j, 1, n) { if((i>>(j-1))&1) luu[++dem]=j; } rep(j, 1, dem) { int state=i^(1ll<<(luu[j]-1)); int xx=1000000000; rep(k1, 1, dem) { if(j==k1) continue; xx=min(xx, c[luu[j]][luu[k1]]); } dp[i]=min(dp[i], dp[state]+xx); } } cout << dp[(1ll<<n)-1]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...