LeetCode 64. Minimum Path Sum

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];
    }
};
posted @   aiterator  阅读(87)  评论(0编辑  收藏  举报
编辑推荐:
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
阅读排行:
· “你见过凌晨四点的洛杉矶吗?”--《我们为什么要睡觉》
· 编程神器Trae:当我用上后,才知道自己的创造力被低估了多少
· C# 从零开始使用Layui.Wpf库开发WPF客户端
· C#/.NET/.NET Core技术前沿周刊 | 第 31 期(2025年3.17-3.23)
· 开发的设计和重构,为开发效率服务
点击右上角即可分享
微信分享提示