답안 #380268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380268 2021-03-20T18:50:39 Z saarang123 Kronican (COCI16_kronican) C++17
100 / 100
717 ms 4716 KB
#include <bits/stdc++.h>
using namespace std;
const int mxn = 21;
int dp[1 << mxn], a[mxn][mxn];
signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    #ifdef saarang
    freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
    freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
    #endif
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    	for(int j = 0; j < n; j++)
    		cin >> a[i][j];
    dp[0] = 0;
    for(int mask = 1; mask < (1 << n); mask++) {
    	dp[mask] = 1e9;
    	for(int i = 0; i < n; i++) if(mask >> i & 1)
    		for(int j = 0; j < n; j++) if(mask >> j & 1) if(i != j)
    			dp[mask] = min(dp[mask], dp[mask ^ (1 << i)] + a[i][j]);
    	if(__builtin_popcount(mask) <= k)
    		dp[mask] = 0;
    }
    cout << dp[(1 << n) - 1] << '\n';
    return 0;
}
# 결과 실행 시간 메모리 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 384 KB Output is correct
5 Correct 8 ms 364 KB Output is correct
6 Correct 16 ms 492 KB Output is correct
7 Correct 33 ms 620 KB Output is correct
8 Correct 73 ms 916 KB Output is correct
9 Correct 712 ms 4588 KB Output is correct
10 Correct 717 ms 4716 KB Output is correct