View Code of Problem 65

# include<stdio.h>
int main(void)
{
  int t,r,i,j,count=0;
  scanf("%d",&t);
  while(count<t)
  {
    scanf("%d",&r);
    int a[r][r];
    for(i=0;i<r;++i)
    {
      for(j=0;j<=i;++j)
      {
          scanf("%d",&a[i][j]);
      }
    }
    for(i=r-2;i>=0;--i)
    {
      for(j=0;j<=i;++j)
      {
        if(a[i+1][j]>=a[i+1][j+1])
        {
          a[i][j] += a[i+1][j];
        }
        else
        {
          a[i][j] += a[i+1][j+1];
        }
      }
    }
    printf("%d\n",a[0][0]);
    ++count;
  }
  return 0;
}

Double click to view unformatted code.


Back to problem 65