#include<bits/stdc++.h>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn
#define bit(n,i) ((n>>i)&1)
using namespace std;
int n, k, f[1<<22];
int c[22][22];
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k;
f0 (i, n) f0 (j, n) cin >> c[i][j];
int ans = 1e9;
for (int x=(1<<n)-1; x; x--)
{
if (x!= (1<<n)-1) f[x] = 1e9;
if (__builtin_popcount(x) < k) continue;
f0 (i, n) if (bit(x, i))
{
f0 (j, n) if (!bit(x, j))
f[x] = min(f[x], f[x+(1<<j)] + c[j][i]);
}
if (__builtin_popcount(x) == k) ans = min(ans, f[x]);
}
cout << ans;
}
Compilation message
kronican.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
6 |
Correct |
12 ms |
340 KB |
Output is correct |
7 |
Correct |
25 ms |
500 KB |
Output is correct |
8 |
Correct |
49 ms |
744 KB |
Output is correct |
9 |
Correct |
488 ms |
4504 KB |
Output is correct |
10 |
Correct |
74 ms |
4428 KB |
Output is correct |