Euler project #18 approach

后端 未结 9 863
鱼传尺愫
鱼传尺愫 2020-11-30 22:23

I am looking into an Euler project. Specifically #18.
To sum up, the idea is to find the max path from a triangle:

   3
  7 4
 2 4 6  
8 5 9 3
<         


        
9条回答
  •  遥遥无期
    2020-11-30 22:52

    Taking a bottom up approach eliminates paths while going top-down only adds potential paths.

    Because you're eliminating bad paths quicker, doing a breadth-first search becomes the optimal solution. A depth-first search in either direction is both wrong (as you've shown) and slow.

提交回复
热议问题