# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98535 | dalgerok | Kronican (COCI16_kronican) | C++17 | 749 ms | 4600 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;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n, m;
cin >> n >> m;
int a[n][n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> a[i][j];
}
}
int dp[(1 << n)];
memset(dp, 63, sizeof(dp));
dp[(1 << n) - 1] = 0;
for(int i = (1 << n) - 1; i >= 0; i--){
for(int j = 0; j < n; j++){
if((i >> j) & 1){
for(int k = 0; k < n; k++){
if(j == k){
continue;
}
if((i >> k) & 1){
dp[i ^ (1 << j)] = min(dp[i ^ (1 << j)], dp[i] + a[j][k]);
}
}
}
}
}
int ans = 2e9;
for(int i = 0; i < (1 << n); i++){
if(__builtin_popcount(i) <= m){
ans = min(ans, dp[i]);
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |