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
<
This is a problem that can be solved using graph theory. For each point, you can only travel to each of it's two 'children' (the left and right node below it). For all of the leaf nodes (the bottom row) include a path to an "end node" (with zero cost).
You want the largest number, which in turn is the longest path.
To do this, you implement a BFS (which is generally a shortest path algorithm), but instead of having the weight between a parent and child node being the value of the child node, you make it be the additive inverse of the child nodes value.
You cannot use Dijkstra easily here because Dijkstra is for non-negative paths only.
BFS has running time of O(|E|+|V|).
In a triangle there are 1+2+3+4+5+..+n = (1/2)(n)(n-1) nodes
This means that there are (n)(n-1) paths, plus the (n) for the final node connection
Total: (1/2) (3n^2 -n) where n is the number of rows.