# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84682 | wjoao | Kronican (COCI16_kronican) | C++11 | 1167 ms | 8884 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 maxn 25
#define maxn2 ((1<<21)+5)
#define inf 0x3f3f3f3f
using namespace std;
int ma[maxn][maxn], pd[maxn2], n, k;
int solve(int bitmask, int count){
if(pd[bitmask] != inf) return pd[bitmask];
if(count >= k) return 0;
for(int i = 0; i < n; i++){
if(bitmask & (1<<i)) continue;
for(int j = 0; j < n; j++){
if(i==j) continue;
if(bitmask & (1<<j)) continue;
pd[bitmask] = min(pd[bitmask],
ma[i][j] + solve(bitmask|(1<<i), count+1)
);
}
}
return pd[bitmask];
}
int main(){
scanf(" %d %d", &n, &k);
memset(pd, inf, sizeof pd);
k = n-k;
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++ )
scanf("%d", &ma[i][j]);
printf("%d\n", solve(0, 0));
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |