@ming54 As you are building the dp matrix, you are essentially calculating the shortest distance to reach that particular point from the top left corner.

So when you are moving to a cell suppose x[i][j], then the cell to it's left (x[i][j-1]) holds the minimum distance value to reach the left cell(x[i][j-1]) from the top left-most corner(x[0][0]).

Similarly, when you are moving to a cell suppose x[i][j], from the cell on it's top (x[i-1][j]), then this agains holds the minimum distance value to reach this cell from the top left-most corner(x[0][0]).

That is why, when you are calculating the distance value to reach cell (x[i][j]), you take the grid value at that position and the minimum of the value from either top or it's left, since that would give the total minimum distance to that position from either moving right or down from the starting position(x[0][0]).

I don't know if my terminology is correct, but you can say it locally, at every point makes a greedy decision, by choosing the minimum. This ties into the properties of a dp problem, that is should have an

Optimal Substructure
Overlapping Subproblems

So the optimal substructure property in a sense means that you can greedily solve the subproblems, and combine them to get the solution to the larger problem.

Just my attempt at trying to explain to you. May not be perfect, since I am not a master at DP, but hope it helps ! :)