View Code of Problem 65

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

Double click to view unformatted code.


Back to problem 65