# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88456 | xiaowuc1 | Kronican (COCI16_kronican) | C++14 | 816 ms | 4820 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;
typedef pair<int, int> edge;
int w[20][20];
int dp[1<<20];
void solve() {
int n, k;
cin >> n >> k;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
cin >> w[i][j];
}
}
int ret = 1 << 30;
for(int mask = 0; mask < (1<<n); mask++) {
dp[mask] = 1 << 30;
}
dp[(1<<n)-1] = 0;
for(int mask = (1<<n)-1; mask >= 0; mask--) {
int bits = __builtin_popcount(mask);
if(bits == k) {
ret = min(ret, dp[mask]);
}
if(bits <= k) continue;
for(int i = 0; i < n; i++) {
if(!(mask&(1<<i))) continue;
for(int j = 0; j < n; j++) {
if(i!=j && (mask&(1<<j))) {
dp[mask^(1<<i)] = min(dp[mask^(1<<i)], dp[mask] + w[i][j]);
}
}
}
}
cout << ret << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |