# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
165926 | _qVp_ | Kronican (COCI16_kronican) | C++14 | 956 ms | 4600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int md = 2e7 + 10;
const int oo = 1e9 + 10;
int f[md];
int n, k, c[30][30];
int getbit(int x, int i) {
return ((x >> i) & 1);
}
//1010011
//0010000
int offbit(int x, int i) {
return ((1 << i) ^ x);
}
int main() {
// freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin >> n >> k;
if (k >= n) {
cout << "0";
return 0;
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++)
cin >> c[i][j];
}
int res = oo;
int ss = (1 << n) - 1;
for(int i = 1; i <= ss; i++)
f[i] = oo;
f[ss] = 0;
for(int s = ss; s >= 1; s--) {
for(int i = 0; i < n; i++)
if (getbit(s, i)) {
int now = offbit(s, i);
for(int j = 0; j < n; j++)
if (getbit(now, j))
f[now] = min(f[now], f[s] + c[i + 1][j + 1]);
}
}
for(int i = 1; i <= ss; i++) {
int cnt = 0;
for(int j = 0; j < n; j++)
cnt += getbit(i, j);
if (cnt == k)
res = min(res, f[i]);
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |