We have a triangle of $n$ positive and integer number. we start from top or (head) of this triangle and in each step we are going to adjacent number in next row. goal is finding path of maximum consecutive number.
example: selected number in following figure has length at most $23$.
the best algorithm for finding this path has order of $O(n^2)$.
It's so not very sensible for me how we can find the path (what is the fastest logical way of solving this puzzle)? $$\begin{array} 0&&&(3)\\ &&(7)&&4\\ &2&&(4)&&6\\ 8&&5&&(9)&&3\end{array}$$
The algorithm to find the largest-sum path in $O(n^2)$ time is as follows:
$$\begin{array} 0&&&3\\ &&7&&4\\ &2&&4&&6\\ 8&&5&&9&&3\end{array}\to \begin{array} 0&&3\\ &7&&4\\ 10L&&13R&&15L\end{array}$$ $$\begin{array} 0&&3\\ &7&&4\\ 10L&&13R&&15L\end{array}\to \begin{array} 0&3\\ 20RR&&19RL\end{array}\to23LRR$$ This works because we are going to pass through the second-last row regardless of what path we take, and in that row the choice we want to make (to maximise the sum) is clear. It is a kind of dynamic programming.