dynamic solution to the minimum sum path problem

the key is to determine the appropriate boundary conditions