# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
367453 | FatihSolak | Kronican (COCI16_kronican) | C++17 | 416 ms | 4588 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 20
using namespace std;
int dist[N][N];
int dp[(1<<N)];
void solve(){
int n,k;
cin >> n >> k;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin >> dist[i][j];
}
}
for(int i=1;i<(1<<n);i++){
dp[i] = 1e9;
}
int ans = 1e9;
for(int i=0;i<(1<<n);i++){
vector<int> un;
for(int j=0;j<n;j++){
if(!(i & (1<<j))){
un.push_back(j);
}
}
if(un.size() == k){
ans = min(ans,dp[i]);
}
for(auto u:un){
int mini = 1e9;
for(auto v:un){
if(u == v)continue;
mini = min(mini,dist[u][v]);
}
dp[i+(1<<u)] = min(dp[i+(1<<u)],dp[i]+mini);
}
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |