1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
inline int max(int a, int b) { return a > b ? a : b; }
inline const int getSum(int Pyramid[100][100], const int &size, const int &row, const int &col)
{
if (row+1 < size)
return Pyramid[row][col] + max( getSum(Pyramid, size, row+1, col ),
getSum(Pyramid, size, row+1, col+1) );
return Pyramid[row][col];
}
int main()
{
int nb_Pyramids, nb_rows, row, col;
int Pyramid[100][100];
std::cin >> nb_Pyramids;
while(nb_Pyramids-- > 0)
{
std::cin >> nb_rows;
for ( row = 0 ; row < nb_rows ; ++row )
for ( col = 0 ; col < row+1 ; ++col )
std::cin >> Pyramid[row][col];
std::cout << getSum(Pyramid, nb_rows,0,0) << std::endl;
}
}
|