# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
973449 | modwwe | Kronican (COCI16_kronican) | C++17 | 708 ms | 8656 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define rep2(i,a,b,c) for (int i=a;i<=b;i+=c)
#define rev(i,a,b) for (int i=a;i>=b;i--)
#define ii pair<int,int>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pb push_back
#define sz(a) (int)(a.size())
#define on(n) __builtin_popcountll(n)
#define ld long double
#define bit(i,j) ((i>>j)&1)
#define oo INT_MAX
const int N=25;
ll n,dp[(1<<20)],c[N][N],k;
void solution(){
cin >> n >> k;
rep(i,1,n){
rep(j,1,n) cin >> c[i][j];
}
memset(dp,0x3f,sizeof(dp));
dp[(1<<n)-1]=0;
rev(mask,(1<<n)-1,0){
rep(j,0,n-1){
if (bit(mask,j)){
ll premask=(mask^(1<<j));
ll cost=1e18;
rep(z,0,n-1){
if (bit(premask,z)) cost=min(cost,c[j+1][z+1]);
}
dp[premask]=min(dp[premask],dp[mask]+cost);
}
}
}
ll res=1e18;
rep(i,0,(1<<n)-1){
if (on(i)==k){
res=min(res,dp[i]);
}
}
cout << res;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
while(t--) solution();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |