![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a343eb0e403d29a776ec9b5330fcb5a9.png)
class Solution {
public:
int minPathSum(vector<vector<int>>& grid) {
vector<vector<int>> dp(grid.size(),vector<int>(grid[0].size(),0));
for(int ii=0;ii<grid.size();ii++){
if(ii==0) dp[ii][0]=grid[ii][0];
else if(ii>0) dp[ii][0]=dp[ii-1][0]+grid[ii][0];
}
for(int jj=1;jj<grid[0].size();jj++){
dp[0][jj]=dp[0][jj-1]+grid[0][jj];
}
for(int ii=1;ii<grid.size();ii++){
for(int jj=1;jj<grid[0].size();jj++){
dp[ii][jj]=min(dp[ii-1][jj]+grid[ii][jj],dp[ii][jj-1]+grid[ii][jj]);
}
}
return dp[grid.size()-1][grid[0].size()-1];
}
};