# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
709873 | mariaclara | Kronican (COCI16_kronican) | C++17 | 675 ms | 8532 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k, dp[(1<<21)], dist[25][25];
int bitcont(int x) {
int cont = 0;
while(x!=0) {
x-=x&-x;
cont++;
}
return cont;
}
int bitmask(int mask) {
//cout << "--------\n" << mask << ":\n";
if(bitcont(mask)==n-k) return 0;
if(dp[mask]!=-1) return dp[mask];
int resp = 1e9;
for(int i = 0; i < n; i++) {
if((1<<i)&mask) continue;
int at = 1e9;
for(int j = 0; j < n; j++)
if(!((1<<j)&mask) and i!=j) at = min(at, dist[i][j]);
//cout << "Volta mask " << mask << ": " << at << " " << i << "\n";
resp = min(resp, at+bitmask(mask+(1<<i)));
}
return dp[mask] = resp;
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
cin >> dist[i][j];
memset(dp, -1, sizeof(dp));
cout << bitmask(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |