# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
584612 | HeyYouNotYouYou | Kronican (COCI16_kronican) | C++14 | 2077 ms | 16844 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>
#define int long long
#define endl '\n'
using namespace std;
const int N = 801,INF=1e12;
int dp[1<<21];
int n , k ;
int arr[21][21];
int count(int n){
return (int)log2(n)+1;
}
int solve(int mask){
if(count(mask)-__builtin_popcount(mask)==k) return 0;
if(dp[mask]!=-1) return dp[mask];
int cur = INT_MAX;
for(int i = 0 ; i < n ; i ++)
for(int j = 0 ; j < n ; j++){
if(i==j) continue;
if(((1<<j)&mask)||((1<<i)&mask)) continue;
cur = min(cur, solve(mask|(1<<i))+arr[i][j]);
}
dp[mask] = cur;
return dp[mask];
}
int32_t main()
{
//freopen("abc.in", "r", stdin);
ios_base::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>>arr[i][j];
}
}
memset(dp,-1,sizeof dp);
cout<<solve((1<<n));
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |