Let F (i, j ) be the largest number of coins the robot can collect and bring to the cell (i, j ) in the ith row and j th column of the board. It can reach this cell either from the adjacent cell (i − 1, j) above it or from the adjacent cell (i, j − 1) to the left of it. The largest numbers of coins that can be brought to these cells
are F (i − 1,j) and F (i, j − 1), respectively. Of course, there are no adjacent cells above the cells in the first row, and there are no adjacent cells to the left of the cells in the first column. For those cells, we assume that F (i − 1,j) and F (i, j − 1) are equal to 0 for their nonexistent neighbors. Therefore, the largest number of
coins the robot can bring to cell (i, j ) is the maximum of these two numbers plus one possible coin at cell (i, j ) itself.