Submission #373106

# Submission time Handle Problem Language Result Execution time Memory
373106 2021-03-03T11:26:00 Z maozkurt Kronican (COCI16_kronican) C++17
0 / 100
42 ms 65540 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <numeric>
#include <cassert>

#define endl '\n'
#define sp ' '

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn = 25;
const int inf = 1e9;
int c[maxn][maxn];
int dp[1<<maxn];

int popcount(int n){
    int ret = 0;
    while(n){
        if(n&1)
            ret++;
        n>>=1;
    }
    return ret;
}
int n,k;
int f(int mask){
    if(popcount(mask) == k)
        return 0;
    if(dp[mask] != -1) 
        return dp[mask];
    int ret = inf;
    for(int i=0;i<n;i++){
        if(mask & (1<<i)){
            for(int j=0;j<n;j++){
                if(i==j)
                    continue;
                if(mask & (1<<j)){
                    ret = min(ret,f(mask ^ (1<<i)) + c[i][j]); 
                }
            }
        }
    }
    return dp[mask] = ret;

}

int main(){
    
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
    
    memset(dp,-1,sizeof dp);
    cin>>n>>k;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>c[i][j];
    cout << f((1<<n)-1) << endl;
}











# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 65540 KB Execution killed with signal 9
2 Runtime error 36 ms 65540 KB Execution killed with signal 9
3 Runtime error 37 ms 65540 KB Execution killed with signal 9
4 Runtime error 40 ms 65540 KB Execution killed with signal 9
5 Runtime error 42 ms 65540 KB Execution killed with signal 9
6 Runtime error 37 ms 65540 KB Execution killed with signal 9
7 Runtime error 39 ms 65540 KB Execution killed with signal 9
8 Runtime error 37 ms 65540 KB Execution killed with signal 9
9 Runtime error 36 ms 65540 KB Execution killed with signal 9
10 Runtime error 34 ms 65536 KB Execution killed with signal 9