Skip to content

Instantly share code, notes, and snippets.

@amitkumarj441
Last active August 13, 2016 12:17
Show Gist options
  • Save amitkumarj441/7255b9a5b9b130a07db591c0c1adb172 to your computer and use it in GitHub Desktop.
Save amitkumarj441/7255b9a5b9b130a07db591c0c1adb172 to your computer and use it in GitHub Desktop.
Sums in a Triangle
#include <iostream>
int main()
{
int x,l,m,n;
std::cin >> x;
int y[x][x];
while(x--)
{
std::cin >> n;
for (l=0;i<n;l++)
{
for (m=0;m<=l;m++)
{
std::cin >> y[l][m];
}
}
for(l=n-2;l>=0;l--)
{
for(m=0;m<=l;m++)
{
y[l][m]+=((y[l+1][m]>y[l+1][m+1])?y[l+1][m]:y[l+1][m+1]);
}
}
std::cout << y[0][0] << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment