# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
584495 | Omar_Elgedawy | Kronican (COCI16_kronican) | C++14 | 1246 ms | 16724 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define cin(vec) for(auto& i : vec) cin >> i
#define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define loop(i,a,b) for (int i = a; i < b; i++)
#define F first
#define S second
#define pb(n) push_back(n)
#define pf(n) push_front(n)
#define dci(d) fixed<<setprecision(d)
#define sp ' '
#define el '\n'
#define all(v) v.begin(),v.end()
#define int long long
int dx[8]= {0,0,1,-1,-1,1,1,-1};
int dy[8]= {-1,1,0,0,-1,1,-1,1};
int const N=1e6,M=21,Mod=1e9;
int dp[1<<M],k,n,a[M][M];
int rec(int mask){
if(__builtin_popcount(mask)==k)return 0;
int &ret=dp[mask];
if(~ret)return ret;
ret=1e9;
for(int i=0;i<n;i++){
if(!(mask&(1<<i)))continue;
for(int j=0;j<n;j++){
if(i==j||!(mask&(1<<j)))continue;
ret=min(ret,rec(mask^(1<<i))+a[i][j]);
}
}
return ret;
}
void testcase(int h){
memset(dp,-1,sizeof dp);
cin>>n>>k;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
cout<<rec((1<<n)-1);
}
int32_t main()
{
// fast
testcase(1);
// int tc;cin>>tc;for(int i=1;i<=tc;i++)testcase(i);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |