# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201577 | SamAnd | Kronican (COCI16_kronican) | C++17 | 643 ms | 4480 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 = 22, INF = 1000000009;
int n, k;
int c[N][N];
int u[N];
int dp[(1 << N)];
int main()
{
//freopen("input.txt", "r", stdin);
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
scanf("%d", &c[i][j]);
}
int ans = INF;
for (int x = 1; x < (1 << n); ++x)
dp[x] = INF;
for (int x = 0; x < (1 << n); ++x)
{
vector<int> v;
for (int i = 0; i < n; ++i)
{
u[i] = INF;
if (!(x & (1 << i)))
v.push_back(i);
}
for (int ii = 0; ii < v.size(); ++ii)
{
int i = v[ii];
for (int jj = 0; jj < v.size(); ++jj)
{
int j = v[jj];
if (i == j)
continue;
u[i] = min(u[i], c[i][j]);
}
}
int q = 0;
for (int i = 0; i < n; ++i)
{
if (!(x & (1 << i)))
{
++q;
dp[(x | (1 << i))] = min(dp[(x | (1 << i))], dp[x] + u[i]);
}
}
if (q == k)
ans = min(ans, dp[x]);
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |