# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334604 | SavicS | Kronican (COCI16_kronican) | C++14 | 702 ms | 8684 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
continue;
}
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... |