How to write this simple algorithm?

problem description

1
3 2
4 6 5
7 9 8 10

from top to bottom, you can only take one step on the left (L) or right (R) at a time, and then add up the numbers to find the path with the maximum value and the maximum value.
how to write this algorithm in python?


has an idea to create a two-dimensional array aux , store the maximum value of the current location, and finally only need to return the maximum value of the entire two-dimensional array.

The

path is finally extrapolated using DFS .

for example, in the example of a topic, the aux created ends up like this

[ [ 1 ], 
  [ 4, 3 ],
  [ 8, 10, 8 ],
  [ 15, 19, 18, 18 ]]

the time complexity is O (1 code 2n ^ 2) , n is the length of the array, here is 4.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3682f-2c02a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3682f-2c02a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?