# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
165766 | asifthegreat | Kronican (COCI16_kronican) | C++14 | 1565 ms | 12156 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 21;
int cost[N][N];
int dp[3000000];
int n,k;
bool Check(int x,int bit){return 1&(x>>bit);}
int Set(int x,int bit){return x|(1<<bit);}
int call(int mask){
if(__builtin_popcount(mask) == n-k)return 0;
if(dp[mask] != -1)return dp[mask];
int &ret = dp[mask];
ret = 1<<30;
for(int i = 0; i < n;i++){
if(Check(mask,i)) continue;
for(int j = 0; j < n;j++){
if(Check(mask,j) or i == j)continue;
// cout << "Hell yah\n";
ret = min(ret, call(Set(mask,j))+cost[j][i]);
}
}
return ret;
}
int main()
{
memset(dp,-1,sizeof dp);
cin >> n >> k;
for(int i = 0; i < n; i++){
for(int j = 0; j < n ;j++){
cin >> cost[i][j];
}
}
int ans = call(0);
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |