Submission #98838

# Submission time Handle Problem Language Result Execution time Memory
98838 2019-02-26T12:28:00 Z sams Kronican (COCI16_kronican) C++14
100 / 100
1317 ms 4480 KB
#include <bits/stdc++.h>
    
using namespace std;
    
const int maxmask = (1<<20)+10, inf = 0x3f3f3f3f;
    
int n, k, m[30][30];
    
int dp[maxmask];
    
int solve(int mask, int qtd){
    
    if(dp[mask] != inf) return dp[mask];
    if(qtd >= k) return 0;
    
    for(int i = 0 ; i < n ; ++i){
        if(mask & (1<<i)) continue;
    
        for(int j = 0 ; j < n ; ++j){
            
            if(i == j) continue;
            if(mask & (1<<j)) continue;
    
            dp[mask] = min(dp[mask], m[i][j] + solve(mask | (1<<i), qtd+1));
        }
    }
    
    return dp[mask];
}
int main(){
    
    cin >> n >> k;
    
    for(int i = 0 ; i < n ; ++i)
        for(int j = 0 ; j < n ; ++j)
            cin >> m[i][j];   
    
    memset(dp, inf, sizeof dp);
    
    k = n - k;
    cout << solve(0, 0) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4352 KB Output is correct
2 Correct 6 ms 4352 KB Output is correct
3 Correct 6 ms 4352 KB Output is correct
4 Correct 7 ms 4352 KB Output is correct
5 Correct 16 ms 4352 KB Output is correct
6 Correct 24 ms 4480 KB Output is correct
7 Correct 49 ms 4352 KB Output is correct
8 Correct 116 ms 4352 KB Output is correct
9 Correct 1317 ms 4472 KB Output is correct
10 Correct 105 ms 4472 KB Output is correct