Submission #334604

# Submission time Handle Problem Language Result Execution time Memory
334604 2020-12-09T14:56:49 Z SavicS Kronican (COCI16_kronican) C++14
100 / 100
702 ms 8684 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 25;
const ll inf = 1e18 + 5;

int n, k;
ll mat[maxn][maxn];

ll dp[(1 << 20)];

int main()
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    cin >> n >> k;
    ff(i,0,n - 1){
        ff(j,0,n - 1)cin >> mat[i][j];
    }
    ff(mask,0,(1 << n) - 1)dp[mask] = inf;
    ff(mask,0,(1 << n) - 1){
        if(__builtin_popcount(mask) <= k){
            dp[mask] = 0;
            continue;
        }
        ff(i,0,n - 1){
            if(mask & (1 << i)){
                ff(j,0,n - 1){
                    if((mask & (1 << j)) && i != j)dp[mask] = min(dp[mask], dp[mask ^ (1 << i)] + mat[i][j]);
                }
            }
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}
/**

9 3
0 7 49 23 8 30 22 44 28
23 0 9 40 15 42 42 37 3
27 29 0 40 12 3 19 9 7
10 33 49 0 28 16 35 47 26
12 17 10 33 0 29 49 29 21
17 22 43 36 35 0 45 28 41
44 7 1 3 8 44 0 18 40
24 46 30 3 22 16 49 0 24
1 3 27 8 28 33 48 31 0

Treba 19 meni izbacuje 25

**/

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 9 ms 492 KB Output is correct
6 Correct 18 ms 620 KB Output is correct
7 Correct 28 ms 876 KB Output is correct
8 Correct 67 ms 1516 KB Output is correct
9 Correct 702 ms 8684 KB Output is correct
10 Correct 64 ms 8556 KB Output is correct