#include <iostream> using namespace std; int main(){ int n,r; scanf("%d",&n); while(n--){ scanf("%d",&r); int m[100][100]; for(int j=0;j<r;j++){ for(int k=0;k<=j;k++){ scanf("%d",&m[j][k]); } } for(int j=r-2;j>=0;j--){ for(int k=0;k<=j;k++) if(m[j+1][k]>m[j+1][k+1]) m[j][k]+=m[j+1][k]; else m[j][k]+=m[j+1][k+1]; } printf("%d\n",m[0][0]); } return 0; } |
Double click to view unformatted code.