原題鏈接
#includeint A[101][101]; int max(int a, int b){ if(a >= b) return a; return b; } int main(){ int n, i, j, temp; while(scanf("%d", &n) == 1){ for(i = 1; i <= n; ++i){ for(j = 1; j <= i; ++j){ scanf("%d", &temp); A[i][j] = max(A[i - 1][j - 1], A[i - 1][j]) + temp; } } for(j = 1, temp = 0; j <= n; ++j) if(A[n][j] > temp) temp = A[n][j]; printf("%d\n", temp); } return 0; }