prestige

Untitled

Mar 12th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #include <algorithm>
  2. #include <bitset>
  3. #include <cassert>
  4. #include <cmath>
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <cstring>
  8. #include <iostream>
  9. #include <list>
  10. #include <map>
  11. #include <queue>
  12. #include <set>
  13. #include <string>
  14. #include <sstream>
  15. #include <vector>
  16. #include <complex>
  17. #include <ctime>
  18. #include <stack>
  19.  
  20. using namespace std;
  21.  
  22. typedef long long ll;
  23. typedef unsigned long long ull;
  24. typedef vector<int> VI;
  25. typedef vector< VI > VVI;
  26. typedef pair<int, int> PII;
  27. typedef vector<PII> VPII;
  28.  
  29. #define REP(i, n) for(int i = 0; i < (n); ++i)
  30. #define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
  31. #define FOR(i, x, y) for(int i = (x); i <= (y); ++i)
  32. #define RFOR(i, x, y) for(int i = (x); i >= (y); --i)
  33. #define SZ(a) (int)(a).size()
  34. #define ALL(a) (a).begin(),(a).end()
  35. #define SORT(a) sort(ALL(a))
  36. #define CLEAR(x) memset(x, 0, sizeof x);
  37. #define COPY(FROM, TO) memcpy(TO, FROM, sizeof TO);
  38. #define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
  39. #define pb push_back
  40. #define mk make_pair
  41. #define sqr(x) ((x)*(x))
  42. #define X first
  43. #define Y second
  44. const long double pi=acos(-1.0);
  45. const double EPS = 1E-5;
  46. const int INF = 2 * (1e+9) + 1;
  47. const int NMAX = 32000;
  48. const int MOD = 1e+25;
  49.  
  50. int n, k;
  51. int a[13][13];
  52. ll dp[1<<13][13];
  53. int main () {
  54. /*freopen("ladder.in", "r" ,stdin);
  55. freopen("ladder.out", "w", stdout);*/
  56. cin >> n;
  57. REP (i, n) REP (j, n) cin >> a[i][j];
  58. FOR (mask, 1, (1<<n) - 1)
  59. REP (j, n)
  60. dp[mask][j] = INF;
  61. FOR (mask, 1, (1<<n) - 1) {
  62. REP (i, n) {
  63. if ((mask & (1<<i)) == 0) {
  64. int cur = (mask | (1<<i));
  65. ll minn = INF;
  66. REP (j, n) {
  67. if (j == i) continue;
  68. ll val = (dp[mask][j] == INF ? 0 : dp[mask][j]);
  69. dp[cur][i] = min (val + a[i][j], dp[cur][i]);
  70. }
  71. }
  72. }
  73. }
  74. ll minn = INF;
  75. REP (i, n)
  76. minn = min (minn, dp[(1<<n) - 1][i]);
  77. cout << minn;
  78. return 0;
  79. }
  80. /*
  81. 5
  82. 0 183 163 173 181
  83. 183 0 165 172 171
  84. 163 165 0 189 302
  85. 173 172 189 0 167
  86. 181 171 302 167 0
  87. */
Advertisement
Add Comment
Please, Sign In to add comment