Maximum path sum II


Fork me on GitHub
2014-09-13

Problem 067: Maximum path sum II

Description:

By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.

3
7 4
2 4 6
8 5 9 3

That is, 3 + 7 + 4 + 9 = 23.

Find the maximum total from top to bottom in triangle.txt (right click and 'Save Link/Target As...'), a 15K text file containing a triangle with one-hundred rows.

NOTE: This is a much more difficult version of [Problem 18]. It is not possible to try every route to solve this problem, as there are 299 altogether! If you could check one trillion (1012) routes every second it would take over twenty billion years to check them all. There is an efficient algorithm to solve it. ;o)


Solution:
  >"d" 00p00g1-20p010p>10g3*:20g1+g"0"-55+*\1+20g1+g"0"-+10g20g1+p10g1+:10p20g-1-#v_20g:1-20p010p#v_v
59                    ^                                                           <               < v
73 41                 v                                                                             <
52 40 09                                                                           > $v
26 53 06 34           >00g2-:10p  20p > 10g20g1+g  10g20g2+g  :  10g1+20g2+g -:0`>#^_-> + 10g20g1+ p   10g:1-10p#v_20g:1-:20p10p#v_  01g.@
10 51 87 86 81                        ^                                                                          <               <
61 95 66 57 25 68
90 81 80 38 92 67 73
30 28 51 76 81 18 75 44
84 14 95 87 62 81 17 78 58

... ... ...
This program is too big to display/execute here, click [download] to get the full program.

Explanation:

see [Problem-018]


Interpreter steps: 650 537
Execution time (BefunExec): 266ms (2.45 MHz)
Program size: 299 x 101
Solution: 7273
Solved at: 2014-09-13



made with vanilla PHP and MySQL, no frameworks, no bootstrap, no unnecessary* javascript