Advertisement
Guest User

Untitled

a guest
Nov 16th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #pragma comment(linker, "/stack:16777216")
  3. #include <string>
  4. #include <vector>
  5. #include <map>
  6. #include <list>
  7. #include <iterator>
  8. #include <set>
  9. #include <queue>
  10. #include <iostream>
  11. #include <sstream>
  12. #include <stack>
  13. #include <deque>
  14. #include <cmath>
  15. #include <memory.h>
  16. #include <cstdlib>
  17. #include <cstdio>
  18. #include <cctype>
  19. #include <algorithm>
  20. #include <utility>
  21. #include <time.h>
  22. using namespace std;
  23.  
  24. #define FOR(i, a, b) for(int i = (a); i < (b); ++i)
  25. #define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
  26. #define REP(i, N) FOR(i, 0, N)
  27. #define RREP(i, N) RFOR(i, N, 0)
  28. #define FILL(A,value) memset(A,value,sizeof(A))
  29.  
  30. #define ALL(V) V.begin(), V.end()
  31. #define SZ(V) (int)V.size()
  32. #define PB push_back
  33. #define MP make_pair
  34. #define Pi 3.14159265358979
  35.  
  36. typedef long long Int;
  37. typedef unsigned long long UINT;
  38. typedef vector <int> VI;
  39. typedef pair <int, int> PII;
  40.  
  41. const int INF = 1000000000;
  42. const int MAX = 128;
  43. const int MAX2 = 7000;
  44. const int BASE = 1000000000;
  45.  
  46. int n, m;
  47. int D[MAX];
  48. int A[MAX][MAX];
  49. int R[MAX][1 << 16][2];
  50.  
  51. int main()
  52. {
  53. #ifndef ONLINE_JUDGE
  54. //freopen("in.txt", "r", stdin);
  55. #endif
  56.  
  57. scanf("%d %d", &n, &m);
  58. FOR (i,0,n)
  59. {
  60. scanf("%d", &D[i]);
  61. FOR (j,0,m)
  62. scanf("%d", &A[i][j]);
  63. }
  64.  
  65. FOR (i,0,n+1)
  66. FOR (j,0,1 << m)
  67. FOR (k,0,2)
  68. R[i][j][k] = INF;
  69. R[0][0][0] = 0;
  70. FOR (i,0,n)
  71. FOR (mask,0,(1 << m))
  72. FOR (b,0,2)
  73. {
  74. if (R[i][mask][b] >= INF)
  75. continue;
  76. R[i+1][mask][0] = min(R[i+1][mask][0], R[i][mask][b]);
  77. FOR (j,0,m)
  78. if ((mask & (1 << j)) == 0)
  79. {
  80. int add = A[i][j];
  81. if (b == 0)
  82. add += D[i];
  83. //cout << add << endl;
  84. R[i][mask | (1 << j)][1] = min(R[i][mask | (1 << j)][1], R[i][mask][b] + add);
  85. }
  86. }
  87. int res = INF;
  88. FOR (i,0,n+1)
  89. FOR (k,0,2)
  90. res = min(res, R[i][(1 << m)-1][k]);
  91. cout << res << endl;
  92.  
  93.  
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement