fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int a, b, arr[98][98], i, j, count=0, i_temp, j_temp, max, max1, max2;
  7. cin>>a;
  8. while(a--) {
  9. arr[98][98]=0;
  10. cin>>b;
  11. count=0;
  12. for(i=0; i<b; i++) {
  13. if(count<b) count++;
  14. for(j=0; j<count; j++) {
  15. cin>>arr[i][j];
  16. }
  17. }
  18. i_temp=i, j_temp=j;
  19. for(; i>0; i--) {
  20. j=j_temp;
  21. for(; j>0; j--) {
  22. max1=arr[i][j-1]+arr[i-1][j-1], max2=arr[i][j]+arr[i-1][j-1];
  23. if(max1>max2) max=max1; else max=max2;
  24. arr[i-1][j-1]=max;
  25. }
  26. j_temp=j_temp-1;
  27. }
  28. cout<<arr[0][0]<<endl;
  29. //arr[100][100]=0;
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0s 3300KB
stdin
1
3
1
2 1
5 4 3
stdout
8