LeetCode 64. Minimum Path Sum

Posted dacc123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 64. Minimum Path Sum相关的知识,希望对你有一定的参考价值。

题目

简单动态规划

class Solution 
public:
    int dp[1005][1005];
    int minPathSum(vector<vector<int>>& grid) 
        
        int n = grid.size();
        int m = grid[0].size();
        dp[0][0]=grid[0][0];
        for(int i=0;i<n;i++)
        
            for(int j=0;j<m;j++)
            
                if(i==0&&j==0)
                    continue;
                if(i==0)
                    dp[i][j] = dp[i][j-1] + grid[i][j];
                    continue;
                
                if(j==0)
                    dp[i][j] = dp[i-1][j] + grid[i][j];
                    continue;
                
                
                dp[i][j] = min(dp[i-1][j],dp[i][j-1]) + grid[i][j];
            
        
        
        return dp[n-1][m-1];
        
    
;

以上是关于LeetCode 64. Minimum Path Sum的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode64 Minimum Path Sum

Leetcode64 Minimum Path Sum

[leetcode-64-Minimum Path Sum]

LeetCode 64. Minimum Path Sum

leetcode 64. Minimum Path Sum

LeetCode64 Minimum Path Sum