// XD XD
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using arr3 = array<int, 3>;
const int MAXN = 13 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e18 + 7;
template <typename T>
bool ckmin(T& a, T b) {
return a > b ? a = b, true : false;
}
template <typename T>
bool ckmax(T& a, T b) {
return a < b ? a = b, true : false;
}
int n, k;
int a[MAXN][MAXN];
int dp[1 << MAXN];
void solve(int id) {
cin >> n >> k;
memset(dp, 0x3f, sizeof dp);
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++) {
for (int i = 0; i < n; i++) {
if (mask >> i & 1) {
for (int j = 0; j < n; j++) {
if (mask >> j & 1 ^ 1)
dp[mask] = min(dp[mask], dp[mask ^ (1 << i)] + a[i][j]);
}
}
}
}
int ans = INF;
for (int i = 0; i < (1 << n); i++) {
if (__builtin_popcount(i) >= n - k) {
ans = min(ans, dp[i]);
}
}
cout << ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
solve(i);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |