Submission #165766

#TimeUsernameProblemLanguageResultExecution timeMemory
165766asifthegreatKronican (COCI16_kronican)C++14
100 / 100
1565 ms12156 KiB
#include <bits/stdc++.h> using namespace std; const int N = 21; int cost[N][N]; int dp[3000000]; int n,k; bool Check(int x,int bit){return 1&(x>>bit);} int Set(int x,int bit){return x|(1<<bit);} int call(int mask){ if(__builtin_popcount(mask) == n-k)return 0; if(dp[mask] != -1)return dp[mask]; int &ret = dp[mask]; ret = 1<<30; for(int i = 0; i < n;i++){ if(Check(mask,i)) continue; for(int j = 0; j < n;j++){ if(Check(mask,j) or i == j)continue; // cout << "Hell yah\n"; ret = min(ret, call(Set(mask,j))+cost[j][i]); } } return ret; } int main() { memset(dp,-1,sizeof dp); cin >> n >> k; for(int i = 0; i < n; i++){ for(int j = 0; j < n ;j++){ cin >> cost[i][j]; } } int ans = call(0); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...