动态规划
class Solution { public: int minPathSum(vector<vector<int> >& matrix) { vector<vector<int>> res(matrix); int row = res.size(), col = res[0].size(); for(int i=1; i<row; ++i) res[i][0] += res[i-1][0]; for(int j=1; j<col; ++j) res[0][j] += res[0][j-1]; for(int i=1; i<row; ++i){ for(int j=1; j<col; ++j) res[i][j] += min(res[i-1][j], res[i][j-1]); } return res[row-1][col-1]; } };