#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL)
#define forw(i, l, r) for( int i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( int i = (r) ; i >= (l) ; i-- )
#define log2i(x) (64 - __builtin_clzll(1ll * (x)) - 1)
#define numBit(x) (__builtin_popcountll(1ll * (x)))
#define getBit(x, i) ((x) >> (i) & 1)
#define Pi acos(-1.0l)
#define sz(x) int(x.size())
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define debug(x) cerr << #x << " = " << x << '\n';
const int N = 20;
const int inf = 0x3f3f3f3f;;
int n, k;
int c[N][N], dp[1 << N];
int main() {
fastIO;
#ifndef ONLINE_JUDGE
//freopen("test.inp","r",stdin);
//freopen("test.out","w",stdout);
#endif
cin >> n >> k;
forw(i, 0, n) forw(j, 0, n) cin >> c[i][j];
dp[(1 << n) - 1] = 0;
forb(i, (1 << n) - 2, 1) {
dp[i] = inf;
forw(j, 0, n) {
if(getBit(i, j)) continue;
forw(k, 0, n) {
if(!getBit(i, k)) continue;
dp[i] = min(dp[i], dp[i + (1 << j)] + c[j][k]);
}
}
}
int ans = inf;
forw(i, 1, 1 << n) if(numBit(i) <= k) ans = min(ans, dp[i]);
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
7 ms |
332 KB |
Output is correct |
6 |
Correct |
15 ms |
448 KB |
Output is correct |
7 |
Correct |
31 ms |
560 KB |
Output is correct |
8 |
Correct |
84 ms |
716 KB |
Output is correct |
9 |
Correct |
662 ms |
4444 KB |
Output is correct |
10 |
Correct |
652 ms |
4348 KB |
Output is correct |