Mylar the robot has a simple life. Its sole purpose is to navigate from the top row of an NxN grid to the bottom row, while consuming as little fuel as possible. Mylar is able to choose its starting column. At each time step, it can select from one of three possible actions: move straight down, or move diagonally down left or right:
If Mylar ever attempts to step off the left or right edge of the grid, it reappears in the appropriate location on the opposite side.
Complicating Mylar's life is the fact that there may be a different fuel cost associated with traversing each cell in the grid. Here is an example grid along with the optimal sequence of decisions (with a total fuel cost of 5):
Your goal is to develop a dynamic programming algorithm that Mylar can use to solve this problem. You should provide an English language description, clear pseudocode (or well-documented code), and a performance analysis. The input to the algorithm is the NxN grid of numbers. The output of the algorithm should be the total fuel usage; you do not need to return the path itself.