# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165766 | asifthegreat | Kronican (COCI16_kronican) | C++14 | 1565 ms | 12156 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |