Submission #959586

# Submission time Handle Problem Language Result Execution time Memory
959586 2024-04-08T13:21:05 Z Beerus13 Kronican (COCI16_kronican) C++14
100 / 100
546 ms 4568 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define bit(mask, i) ((mask >> i) & 1)
const int N = 1 << 20;

int n, k;
int a[20][20], dp[N + 5];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) cin >> a[i][j];
    memset(dp, 0x3f, sizeof(dp));
    dp[(1 << n) - 1] = 0;
    for(int mask = (1 << n) - 1; mask; --mask) {
        for(int i = 0; i < n; ++i) if(bit(mask, i)) {
            for(int j = 0; j < n; ++j) if(!bit(mask, j)) {
                int pre = mask | (1 << j);
                dp[mask] = min(dp[mask], dp[pre] + a[j][i]);
            }
        }
    }
    int ans = 1e9;
    for(int mask = 0; mask < (1 << n); ++mask) {
        if(__builtin_popcount(mask) <= k) ans = min(ans, dp[mask]);
    }
    return cout << ans, 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 7 ms 4564 KB Output is correct
6 Correct 15 ms 4440 KB Output is correct
7 Correct 27 ms 4568 KB Output is correct
8 Correct 56 ms 4440 KB Output is correct
9 Correct 532 ms 4440 KB Output is correct
10 Correct 546 ms 4548 KB Output is correct