Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.
简单dp
class Solution {
public:
int minPathSum(vector<vector<int>>& grid) {
int x = grid.size(), y = grid[0].size();
vector<vector<unsigned int>> dp(x+1, vector<unsigned int>(y+1, INT_MAX));
dp[0][1] = dp[1][0] = 0;
for(int i=1; i<x+1; ++ i)
{
for(int j=1; j<y+1; ++ j)
dp[i][j] = grid[i-1][j-1] + min(dp[i-1][j], dp[i][j-1]);
}
return dp[x][y];
}
};