// dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + dp[i][j];
// 注意初始化横竖累和
class Solution {
public int minPathSum(int[][] grid) {
int n = grid.length;
int m = grid[0].length;
for (int i = 1;i < n; i++)
grid[i][0] += grid[i - 1][0];
for (int j = 1;j < m; j ++)
grid[0][j] += grid[0][j - 1];
for (int i = 1;i < n; i++){
for (int j = 1;j < m; j++){
grid[i][j] += Math.min(grid[i - 1][j], grid[i][j - 1]);
}
}
return grid[n - 1][m - 1];
}
}