Image

Imagewebspiderus wrote in Imagecpp

hi
i've been given a problem, and it has stumped me for the past few days. the gist of it is as follows:
you have a pyramid of numbers, like one shown below
2
4 1
3 5 9
4 5 8 9
there can be up to 100 lines, and the numbers can range from 1 to 99. the goal is to start at the top and end up somewhere on the base such that the sum of the numbers in your path is the greatest. the pyramid is given to you in a text file, where the first line is the number of rows, and the rest is the pyramid. the top example would look like this:
4
2
4 1
3 5 9
4 5 8 9
i can get an idea of how to do this for a small number of rows, but am at a loss when the amount of lines becomes big, seeing that it can be maxed up to 100.
thank you for any help given.
EDIT:
one can only go on diagonals, so from 2 to 4 or 1, from 4 to 3 or 5, so on. you cannot jump to any number on the next line.