|
Problem # 11 : The Jackpot Path
A number triangle is shown below.
Write a function which calculates the highest sum of numbers passed
on a route that begins at the top and ends somewhere on the base. The route
must follow these rules:
a) Each step of the route can go diagonally down to the left or diagonally
down to the right
b) The number of rows will not more that 100
c) The numbers in the triangle are integers between 0 and 99
The function BESTSUM(Rows
Triange()) is passed
Rows - number of rows in the triangle
Triangle() - an double-dimension array containing the values in the triangle
Sample Output
For the triangle drawn above
Rows=5
The Triangle() array contains these values
| 7 |
0 |
0 |
0 |
0 |
| 3 |
8 |
0 |
0 |
0 |
| 8 |
1 |
0 |
0 |
0 |
| 2 |
7 |
4 |
4 |
0 |
| 4 |
5 |
6 |
2 |
5 |
BESTSUM(Rows
Triangle()) should return 30
[30
the highest sum is obtained by the route- 7+3+8+7+5 (highlighted in picture)]
|