Advertisement
hasib_mo

Untitled

Mar 20th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1.  
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<cstdlib>
  6. #include<cmath>
  7.  
  8. #include<algorithm>
  9. #include<vector>
  10. #include<string>
  11. #include<stack>
  12. #include<queue>
  13. #include<map>
  14. #include<sstream>
  15.  
  16.  
  17.  
  18. #define FOR(i, s, e) for(int i=s; i<e; i++)
  19. #define loop(i, n) for(int i=0; i<n; i++)
  20. #define getint(n) scanf("%d", &n)
  21. #define pb(a) push_back(a)
  22. #define ll long long
  23. #define SZ(a) int(a.size())
  24. #define read() freopen("input.txt", "r", stdin)
  25. #define write() freopen("output.txt", "w", stdout)
  26. #define mem(a, v) memset(a, v, sizeof(a))
  27. #define all(v) v.begin(), v.end()
  28. #define pi acos(-1.0)
  29. #define INF 1<<29
  30. #define mod abs
  31. #define pf printf
  32. #define sf scanf
  33.  
  34. using namespace std;
  35.  
  36. #define MAXX 10
  37.  
  38. int grid[MAXX][MAXX];
  39. int dp[1<<MAXX][1<<MAXX];
  40. int N;
  41.  
  42. int rec(int alice, int bob)
  43. {
  44.  
  45.     int &ret = dp[alice][bob];
  46.  
  47.     if(ret != -1) return ret;
  48.  
  49.  
  50.     ret = -INF;
  51.  
  52.     loop(i, N)
  53.     {
  54.         if( !(alice & (1<<i)) )
  55.         {
  56.             loop(j, N)
  57.             {
  58.                 if( ! (bob & (1<<j)) )
  59.                 {
  60.                     ret = max(ret,  grid[i][j] + rec((alice | 1<<i), (bob | 1<<j)) );
  61.                 }
  62.             }
  63.         }
  64.     }
  65.     return ret;
  66.  
  67. }
  68.  
  69.  
  70. int main()
  71. {
  72.     int kases;
  73.     getint(kases);
  74.  
  75.     while(kases--)
  76.     {
  77.         getint(N);
  78.         loop(i, N)
  79.         {
  80.             loop(j, N)
  81.             {
  82.                 getint(grid[i][j]);
  83.             }
  84.         }
  85.  
  86.         mem(dp, -1);
  87.  
  88.         dp[1<<N - 1][1<<N - 1] = 0;
  89.  
  90.         pf("%d\n", -rec(0, 0));
  91.  
  92.     }
  93.  
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement