# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84682 | 2018-11-16T13:53:59 Z | wjoao | Kronican (COCI16_kronican) | C++11 | 1167 ms | 8884 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 8568 KB | Output is correct |
2 | Correct | 10 ms | 8692 KB | Output is correct |
3 | Correct | 9 ms | 8740 KB | Output is correct |
4 | Correct | 10 ms | 8740 KB | Output is correct |
5 | Correct | 18 ms | 8820 KB | Output is correct |
6 | Correct | 29 ms | 8820 KB | Output is correct |
7 | Correct | 51 ms | 8884 KB | Output is correct |
8 | Correct | 109 ms | 8884 KB | Output is correct |
9 | Correct | 1167 ms | 8884 KB | Output is correct |
10 | Correct | 115 ms | 8884 KB | Output is correct |