Shortest Path Using Dynamic Programming