fork download
  1. #include<stdio.h>
  2. #define max 100
  3. int a[max][max];
  4. int main(){
  5. int c,d,t=0,e,n,m,f,g,h,i;
  6.  
  7. scanf("%d",&c);// test cases
  8. for(d=1;d<=c;d++){
  9. scanf("%d",&e);// no. of input rows
  10. for(m=0;m<e;m++){
  11. for(n=0;n<=m;n++)
  12. scanf("%d",&a[m][n]);
  13. }
  14. for(f=e-1;f>0;f--){// logic
  15. for(g=0;g<f;g++){
  16. h= a[f][g]+ a[f-1][g];
  17. i= a[f][g+1] + a[f-1][g];
  18. if(h>i)
  19. a[f-1][g]= h;
  20. else
  21. a[f-1][g]= i;
  22. }
  23. }
  24. printf("%d\n",a[0][0]);
  25. t++;
  26. }
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 2892KB
stdin
2
3
1
2 1
1 2 3
4 
1 
1 2 
4 1 2
2 3 1 1 
stdout
5
9