#include<stdio.h> int main() { int n; scanf("%d",&n); while (n--) { int x; scanf("%d",&x); int a[100][100] = { 0 }; for (int i = 0; i < x; i++) { for (int j = 0; j <= i; j++) { scanf("%d",&a[i][j]); } } for (int j = x-1; j >0; j--) { for (int k = 0; k < j; k++) { if (a[j][k] < a[j][k + 1]) { a[j - 1][k] = a[j][k + 1] + a[j - 1][k]; } else { a[j - 1][k] = a[j][k] + a[j - 1][k]; } } } printf("%d\n",a[0][0]); } } |
Double click to view unformatted code.