9 lines
422 B
Python
9 lines
422 B
Python
|
|
from triangledata import *
|
||
|
|
|
||
|
|
# traverse the triangle from the second-to-bottom row, upwards
|
||
|
|
for i in reversed(range(len(dataTable) - 1)):
|
||
|
|
for j in range(i + 1):
|
||
|
|
# set the value of the current node to be the higher sum of the two possible children
|
||
|
|
dataTable[i][j] += max(dataTable[i + 1][j], dataTable[i + 1][j + 1])
|
||
|
|
|
||
|
|
print("The maximum sum from top to bottom of the triangle is: ", str(dataTable[0][0]))
|