# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334600 | SavicS | Kronican (COCI16_kronican) | C++14 | 850 ms | 8684 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 fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 25;
const ll inf = 1e18 + 5;
int n, k;
ll mat[maxn][maxn];
ll dp[(1 << 20)];
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> n >> k;
ff(i,0,n - 1){
ff(j,0,n - 1)cin >> mat[i][j];
}
ff(mask,0,(1 << n) - 1)dp[mask] = inf;
ff(mask,0,(1 << n) - 1){
if(__builtin_popcount(mask) == k)dp[mask] = 0;
ff(i,0,n - 1){
if(mask & (1 << i)){
ff(j,0,n - 1){
if((mask & (1 << j)) && i != j)dp[mask] = min(dp[mask], dp[mask ^ (1 << i)] + mat[i][j]);
}
}
}
}
cout << dp[(1 << n) - 1] << endl;
return 0;
}
/**
9 3
0 7 49 23 8 30 22 44 28
23 0 9 40 15 42 42 37 3
27 29 0 40 12 3 19 9 7
10 33 49 0 28 16 35 47 26
12 17 10 33 0 29 49 29 21
17 22 43 36 35 0 45 28 41
44 7 1 3 8 44 0 18 40
24 46 30 3 22 16 49 0 24
1 3 27 8 28 33 48 31 0
Treba 19 meni izbacuje 25
**/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |