Guest User

Untitled

a guest
Nov 26th, 2016
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. #define OO 9999999999999999LL
  5. ll n, k, dp[1 << 21], a[22][22], res;
  6. ll solve(ll mask,ll on)
  7. {
  8. if (on == k)return 0;
  9. ll ans = OO, &r = dp[mask],sh;
  10. if (r != -1)return r;
  11. for (int i = 0; (1 << i) <= mask; i++)
  12. {
  13. if (((1 << i)&mask)==0)
  14. continue;
  15. for (int j = 0; (1 << j) <= mask; j++)
  16. {
  17. if (((1 << j)&mask)==0)
  18. continue;
  19. if (i == j)
  20. continue;
  21. //cout << "jdfkdjf";
  22. sh = solve((mask - (1 << i)), on - 1)+a[i][j];
  23. //if (sh == 0)cout << i << " " << j << endl;
  24. ans = min(ans, sh);
  25. }
  26. }
  27. return r=ans;
  28. }
  29. int main()
  30. {
  31. ios::sync_with_stdio(false);
  32. cin.tie(0);
  33. cout.tie(0);
  34. memset(dp, -1, sizeof dp);
  35. cin >> n >> k;
  36. for (int i = 0; i < n;i++)
  37. for (int j = 0; j < n; j++)
  38. cin >> a[i][j];
  39. ll e = (1 << n);
  40. e--;
  41. res = solve(e,n);
  42. cout << res << "\n";
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment