# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98470 | pamaj | Kronican (COCI16_kronican) | C++14 | 44 ms | 33792 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 maxn = 20;
int n, k;
int c[maxn][maxn];
int dp[1 << 20][maxn];
int dist[maxn][maxn];
int solve(int mask, int val)
{
if(val <= 0) return 0;
if(dp[mask][val] != -1) return dp[mask][val];
int ans = 1e9;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(i == j or (mask & (1 << i)) or (mask & (1 << j))) continue;
ans = min(ans, solve(mask | (1 << i), val - 1) + c[i][j]);
}
}
return dp[mask][val] = ans;
}
int main()
{
cin >> n >> k;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
cin >> c[i][j];
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(i == 0) continue;
dist[i][j] = 1e9;
}
}
memset(dp, -1, sizeof(dp));
cout << solve(0, n - k) << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |