Dynamic Programming
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.
C++实现代码:
#include#include using namespace std;class Solution {public: int minPathSum(vector > &grid) { if(grid.empty()||grid[0].empty()) return 0; int m=grid.size(); int n=grid[0].size(); int i,j; for(i=1;i