Guest User

Untitled

a guest
Jun 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define pb push_back
  5. #define eb emplace_back
  6. #define all(x) x.begin(), x.end()
  7. #define debug(x) cerr << #x <<": " << (x) << endl
  8. //在每个函数的入口处执行一次,出口处执行一次。然后就可以快速得知是哪个地方段错误了
  9. #define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
  10. #ifdef LOCAL
  11. #define see(x) cout << #x << ": " << (x) << endl
  12. #endif
  13. #ifndef LOCAL
  14. #define see(x)
  15. #endif
  16.  
  17. #define RED "\033[31m"
  18. #define RESET "\033[0m"
  19. #define alert(x) cerr << RED << x << RESET << endl
  20. #ifndef LOCAL
  21. #define see(x)
  22. #endif
  23.  
  24. #define Rep(n) for(int _ = 0; _ != (n); ++_)
  25. #define rep(i, a, b) for(int i = (a); i <= (b); ++i)
  26. #define Rng(i, n) for(int i = 0; i != (n); ++i)
  27. #define rng(i, a, b) for(int i = (a); i != (b); ++i)
  28. #define RNG(i, a) for(auto &i: (a))
  29.  
  30. template<class T> int sign(const T &a) { return a == 0 ? 0 : a > 0 ? 1 : -1; }
  31. template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
  32. template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
  33. template<class T> void Min(T &a, const T &b){ a = min(a, b); }
  34. template<class T> void Max(T &a, const T &b){ b = max(a, b); }
  35.  
  36. template<typename T> void println(const T &t) { cout << t << '\n'; }
  37. template<typename T, typename ...Args> void println(const T &t, const Args &...rest) { cout << t << ' '; println(rest...); }
  38.  
  39. template<typename T> void print(const T &t) { cout << t << ' '; }
  40.  
  41. template<typename T, typename ...Args> void print(const T &t, const Args &...rest) { cout << t; print(rest...); }
  42.  
  43. // this overload is chosen when there's only one argument
  44. template<class T> void scan(T &t) { cin >> t; }
  45. template<class T, class ...Args> void scan(T &a, Args &...rest) { cin >> a; scan(rest...); }
  46.  
  47.  
  48. int cas;
  49. const double pi = acos(-1);
  50. int mod = 1e9 + 7;
  51.  
  52. template<class T>
  53. void add_mod(T &a, const T &b) {
  54. a += b;
  55. if (a >= mod) a -= mod;
  56. }
  57.  
  58.  
  59. using ll = long long;
  60. using ull = unsigned long long;
  61. using vec = vector<ll>;
  62. using mat = vector<vec>;
  63. using pii = pair<int, int>;
  64. using pdd = pair<double, double>;
  65. using pip = pair<int, pii>;
  66. using szt = size_t;
  67. using vi = vector<int>;
  68. using vb = vector<bool>;
  69. using vpii = vector<pii>;
  70.  
  71. mat operator*(const mat &a, const mat &b) {
  72. mat c(a.size(), vec(b[0].size()));
  73. for (int i = 0; i < a.size(); i++) {
  74. for (int j = 0; j < a[0].size(); j++) {
  75. if (a[i][j]) { // optimization for sparse matrix
  76. for (int k = 0; k < b[0].size(); k++) {
  77. add_mod(c[i][k], a[i][j] * b[j][k] % mod);
  78. }
  79. }
  80. }
  81. }
  82. return c;
  83. }
  84.  
  85. vec operator*(const mat &a, const vec &b) {
  86. vec c(a.size());
  87. for (int i = 0; i < a.size(); i++) {
  88. for (int j = 0; j < a[0].size(); j++) {
  89. add_mod(c[i], a[i][j] * b[j] % mod);
  90. }
  91. }
  92. return c;
  93. }
  94.  
  95. mat pow(mat a, ull n) {
  96. mat res(a.size(), vec(a[0].size()));
  97. for (int i = 0; i < a.size(); i++) {
  98. res[i][i] = 1;
  99. }
  100. while (n) {
  101. if (n & 1) {
  102. res = res * a;
  103. }
  104. a = a * a;
  105. n >>= 1;
  106. }
  107. return res;
  108. }
  109.  
  110.  
  111. ll POW(ll x, ll n) {
  112. ll res = 1;
  113. for (; n; n /= 2, x *= x, x %= mod) {
  114. if (n & 1) {
  115. res *= x;
  116. res %= mod;
  117. }
  118. }
  119. return res;
  120. }
  121.  
  122. ll inv(ll x) {
  123. return POW(x, mod - 2);
  124. }
  125.  
  126.  
  127.  
  128. // 2D rotation
  129. void rotate(double &x, double &y, double theta) {
  130. double tx = cos(theta) * x - sin(theta) * y;
  131. double ty = sin(theta) * x + cos(theta) * y;
  132. x = tx, y = ty;
  133. }
  134.  
  135. const int BIT_N = 1e5+5;
  136.  
  137. int bit[BIT_N];
  138.  
  139. int sum(int x) {
  140. int res = 0;
  141. while (x) {
  142. res += bit[x];
  143. x -= x & -x;
  144. }
  145. return res;
  146. }
  147.  
  148. int sum(int l, int r) {
  149. if (l > r) return 0;
  150. return sum(r) - sum(l - 1);
  151. }
  152.  
  153. void add(int x, int v, int n) {
  154. while (x <= n) {
  155. bit[x] += v;
  156. x += x & -x;
  157. }
  158. }
  159.  
  160.  
  161.  
  162. // #include <ext/pb_ds/priority_queue.hpp>
  163.  
  164. // typedef __gnu_pbds :: priority_queue<pip, less<pip>, __gnu_pbds::thin_heap_tag > Heap;
  165.  
  166. // Heap h;
  167.  
  168. // Heap::point_iterator pos[N][N];
  169. const ll INF = LLONG_MAX/10;
  170. const int M = 3000 + 5;
  171.  
  172.  
  173.  
  174. //Clang-Tidy: Prefer transparent functors 'greater<>'
  175.  
  176.  
  177. const int N = 1e3+5;
  178.  
  179.  
  180.  
  181.  
  182. ll dp[N][N][8];
  183.  
  184. ll a[N][3];
  185.  
  186. // 被卡IO了
  187. int main() {
  188. // Single Cut of Failure taut me
  189. cout << setprecision(10) << std::fixed; // std::fixed 使得所有实数(默认)输出6位小数,即使实际小数位数多于6位。
  190. ios::sync_with_stdio(false);
  191. cin.tie(nullptr);
  192. #ifdef LOCAL
  193. freopen("main.in", "r", stdin);
  194. // freopen("main.out", "w", stdout);
  195. #endif
  196.  
  197.  
  198.  
  199. int n, m;
  200. scan(n, m);
  201.  
  202.  
  203. rep(i, 1, n){
  204. rng(j, 0, 3) {
  205. scan(a[i][j]);
  206. }
  207. }
  208.  
  209. // rep(i, 0, n) rep(j, 0, n) rng(k, 0, 16) dp[i][j][k] = -INF;
  210. // dp[0][0][0] = 0;
  211.  
  212. rng(i, 0, n) {
  213. rep(j, 0, m) {
  214. rng(s1, 0, 16){
  215. ll t = dp[i][j][s1];
  216. if(j == m){
  217. Max(dp[i+1][j][s1], t);
  218. }
  219. else{
  220. rng(s2, 0, 16) {
  221. ll &u = dp[i+1][j][s2];
  222. Max(u, dp[i][j][s2]);
  223. rng(k, 0, 3) {
  224. if()
  225. auto sig = (sign(a[i+1][k]) >= 0);
  226. if(sig == bool(s2 & (1<<k))){
  227. t += a[i][k];
  228. }
  229. else t -= a[i][k];
  230. }
  231. }
  232. }
  233. };
  234. }
  235. rng(s1, 0, 16) {
  236. }
  237. }
  238.  
  239.  
  240.  
  241. return 0;
  242. }
Add Comment
Please, Sign In to add comment