#include<iostream> #include<cstring> #include<string> #include<algorithm> #include<vector> using namespace std; int main() { int n; int a[999][999]; int t; cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { cin >> a[i][j]; } } for (int i = n - 1; i >= 0; i--) { for (int j = 0; j <= i; j++) { if (a[i][j] > a[i][j + 1]) a[i - 1][j] = a[i - 1][j] + a[i][j]; else a[i - 1][j] = a[i - 1][j] + a[i][j + 1]; } } cout << a[0][0]<<"\n"; } return 0; } |
Double click to view unformatted code.