fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. ll n,f[2000006],a[22][22];
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  8. freopen("QUEUE.inp", "r", stdin);
  9. freopen("QUEUE.out", "w", stdout);
  10. cin >> n;
  11. for(int i = 0; i < n; i++)
  12. for(int j = 0; j < n; j++)
  13. {
  14. cin >> a[i][j];
  15. }
  16. memset(f, -0x3f, sizeof f);
  17. ll tt = (1<<n)-1;
  18. f[0] = 0;
  19. for(int i = 0; i < tt; i++)
  20. {
  21. ll d = __builtin_popcount(i);
  22. for(int j = 0; j < n; j++)
  23. {
  24. if(!((i>>j)&1))
  25. {
  26. ll p = i | (1<<j);
  27. f[p] = max(f[p],f[i] + a[j][d]);
  28. }
  29. }
  30. }
  31. cout << f[tt];
  32. }
  33.  
Success #stdin #stdout 0.01s 19332KB
stdin
Standard input is empty
stdout
Standard output is empty