Last active
August 13, 2016 12:17
-
-
Save amitkumarj441/7255b9a5b9b130a07db591c0c1adb172 to your computer and use it in GitHub Desktop.
Sums in a Triangle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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