Submission #447317

# Submission time Handle Problem Language Result Execution time Memory
447317 2021-07-26T04:35:24 Z KDisabledA Kronican (COCI16_kronican) C++14
100 / 100
1249 ms 16728 KB
#include<bits/stdc++.h>
#include<ext/numeric>
#define fastIO                  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
#define FOR(i, j, k, in)		for (int i = (j); i < (k); i += (in))
#define FORW(i, j, k, in)		for (int i = (j); i <= (k); i += (in))
#define RFOR(i, j, k, in)		for (int i = (j); i >= (k); i -= (in))
#define RFORW(i, j, k, in)		for (int i = (j); i > (k); i -= (in))
#define sz(arr)                 ((int)(arr).size())
#define pb                      push_back
#define fi						first
#define se						second
#define mp						make_pair

using namespace std;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef pair<int,pii> piii;
typedef vector<pii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const int inf=INT_MAX-(13*7);
const float PI=acos(-1);
const ll linf=LLONG_MAX-(13ll*7ll);
const int N=22;
int n,k;
int a[N][N];
int dp[1<<N];
int f(int mask){
    if(__builtin_popcount(mask) == k) return 0;
    if(dp[mask]!=-1) return dp[mask];
    dp[mask]=1<<30;
    FOR(i,0,n,1){
        if(!(mask&(1<<i))) continue;
        FOR(j,0,n,1){
            if(i==j) continue;
            if(!(mask&(1<<j))) continue;
            dp[mask] = min(dp[mask],f(mask^(1<<i))+a[i][j]);
        }
    }
    return dp[mask];
}
int main(){
   
    fastIO;
    cin>>n>>k;
    memset(dp,-1,sizeof dp);
    FOR(i,0,n,1){
        FOR(j,0,n,1){
            cin>>a[i][j];
        }
    }
    cout<<f((1<<n)-1);
}

//-T nghi la t khong the de mat 1 nguoi ban tot nhu m dau =)))
//
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16716 KB Output is correct
2 Correct 7 ms 16716 KB Output is correct
3 Correct 7 ms 16716 KB Output is correct
4 Correct 7 ms 16716 KB Output is correct
5 Correct 16 ms 16724 KB Output is correct
6 Correct 29 ms 16728 KB Output is correct
7 Correct 50 ms 16716 KB Output is correct
8 Correct 104 ms 16716 KB Output is correct
9 Correct 1249 ms 16716 KB Output is correct
10 Correct 110 ms 16716 KB Output is correct