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.
思路:看到这道题想到两种方法,第一种是分支限界,不过时间复杂度比较高,估计会超时,另一种方法是动态规划,时间复杂度为O(m*n,代码如下:
1 class Solution { 2 public: 3 vector> mi; 4 int minPathSum(vector > &grid) { 5 mi=grid; 6 for(int i=1;i