Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #pragma GCC optimize("-Ofast")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
- #pragma GCC optimize("-ffast-math")
- #pragma GCC optimize("-funroll-loops")
- #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- const long long MOD = 1e9 + 7, OO = 1e18;
- const double PI = acos(-1);
- const int N = 1e2 + 5;
- const int dx[4] = {0, 0, 1, -1};
- const int dy[4] = {1, -1, 0, 0};
- long long t, n, x, a[N][N], mem[N][N];
- long long maxSum(long long i, long long j) {
- if (i == n + 1)return 0;
- long long &ret = mem[i][j];
- if (~ret)return ret;
- long long c1 = maxSum(i + 1, j);
- long long c2 = maxSum(i + 1, j + 1);
- return ret = a[i][j] + max(c1, c2);
- }
- int main() {
- scanf("%lld", &t);
- while (t--) {
- memset(mem, -1, sizeof mem);
- scanf("%lld", &n);
- for (int i = 1; i <= n; i++)
- for (int j = 1; j <= i; j++)scanf("%lld", &a[i][j]);
- printf("%lld\n", maxSum(1LL, 1LL));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment