fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define Fast \
  5.   ios_base::sync_with_stdio(false); \
  6.   cin.tie(NULL);
  7. void input()
  8. {
  9. if (fopen("stdin.txt", "r"))
  10. {
  11. freopen("stdin.txt", "r", stdin);
  12. freopen("stdout.txt", "w", stdout);
  13. }
  14. }
  15. const ll mod = 1e9 + 7;
  16. const int N = 100 + 5;
  17. const int M = 100000 + 5;
  18. ll dp[M][4];
  19. int main()
  20. {
  21. Fast;
  22. input();
  23. memset(dp, -1, sizeof dp);
  24. int n;
  25. cin >> n;
  26. int mx = -1e9;
  27. vector<vector<int>> v(n, vector<int>(3));
  28. for (int i = 0; i < n; i++)
  29. {
  30. for (int j = 0; j < 3; j++)
  31. cin >> v[i][j];
  32. }
  33. function<ll(int, int)> rec = [&](int i, int j) -> ll
  34. {
  35. if (i == n)
  36. return 0;
  37. if (~dp[i][j])
  38. return dp[i][j];
  39. ll sum = -1e9;
  40. for (int x = 0; x < 3; x++)
  41. {
  42. if (x == j)
  43. continue;
  44. sum = max(sum, v[i][x] + rec(i + 1, x));
  45. }
  46. return dp[i][j] = sum;
  47. };
  48. cout << rec(0, 0);
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 7624KB
stdin
Standard input is empty
stdout
Standard output is empty