#include<stdio.h> int main(){ int n; scanf("%d",&n); while(n--){ int r; scanf("%d",&r);//表示行数 int a[r][r]; for(int i=0;i<r;i++){ for(int j=0;j<=i;j++){ scanf("%d",&a[i][j]); } } //现在设置循环开始判断 //从最后一层开始 for(int i=r-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][j+1]; }else{ a[i-1][j]+=a[i][j]; } } } printf("%d\n",a[0][0]); } return 0; } |
Double click to view unformatted code.