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.

class Solution {
public:
int minPathSum(vector<vector<int>> &grid) {
if(grid.empty()) return ; vector<vector<int>> dp(grid.size(), vector<int>(grid[].size(), ));
dp[][] = grid[][];
for(int i = ; i< grid[].size(); i++)
{
dp[][i] = dp[][i-] + grid[][i];
}
for(int i = ; i< grid.size(); i++)
{
dp[i][] = dp[i-][] + grid[i][];
} for(int i = ;i<grid.size(); i++)
{
for(int j = ; j< grid[].size(); j++)
{
dp[i][j] = min(dp[i-][j], dp[i][j-]) + grid[i][j];
}
}
return dp[grid.size()-][grid[].size()-];
}
};

64. Minimum Path Sum (Graph; DP)的更多相关文章

  1. 刷题64. Minimum Path Sum

    一.题目说明 题目64. Minimum Path Sum,给一个m*n矩阵,每个元素的值非负,计算从左上角到右下角的最小路径和.难度是Medium! 二.我的解答 乍一看,这个是计算最短路径的,迪杰 ...

  2. leecode 每日解题思路 64 Minimum Path Sum

    题目描述: 题目链接:64 Minimum Path Sum 问题是要求在一个全为正整数的 m X n 的矩阵中, 取一条从左上为起点, 走到右下为重点的路径, (前进方向只能向左或者向右),求一条所 ...

  3. 【LeetCode】64. Minimum Path Sum

    Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to b ...

  4. [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 ...

  5. 64. Minimum Path Sum(中等, 又做出一个DP题, 你们非问我开不开心,当然开心喽!^^)

    Given an m x n grid filled with nonnegative numbers, find a path from top left to bottom right which ...

  6. [leetcode DP]64. Minimum Path Sum

    一个m*n的表格,每个格子有一个非负数,求从左上到右下最短的路径值 和62,63两个值是同一个思路,建立dp表,记录每个位置到右下角的最短路径的值 class Solution(object): de ...

  7. [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 ...

  8. LeetCode 64 Minimum Path Sum

    Problem: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom ri ...

  9. 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 ...

随机推荐

  1. linux screen 命令详解(转载)

    转载于:http://www.cnblogs.com/mchina/archive/2013/01/30/2880680.html 一.背景 系统管理员经常需要SSH 或者telent 远程登录到Li ...

  2. [QT]问题记录-QPixmap::scaled 缩放不成功

    解答的帖子: http://bbs.csdn.net/topics/391850818 使用 pix.scaled(400,400)  之后需要将图片返回就可以了.

  3. mongodb启用Profiling定位问题

    建议使用方法三,最简单且容易查看 一:如果mongodb已经运行了很长时间,此时查看mongod.log很大,没法打开查看相应信息 #ps -ef|grep mongod 找到相应的mongod的进程 ...

  4. streamsets Processors 说明

    Processors 表示对于一种数据操作处理,在pipeline中可以应用多个Processors, 同时根据不同的执行模式,可以分为独立模式的,集群模式.边缘模式(agent),以及 帮助测试的测 ...

  5. linux环境下git的安装配置

    1.查看git的最新版本: 查看最新版git:访问https://www.kernel.org/pub/software/scm/git/或者https://github.com/git/git/re ...

  6. FastAdmin 学习线路 (2018-06-09 更新)

    FastAdmin 学习线路 以下为常规线路,非常规可跳过. FastAdmin 学习线路 基础 HTML CSS DIV Javascript 基础 jQuery php 基础 对象 命名空间 进阶 ...

  7. java.nio.charset.UnsupportedCharsetException: cp0

    使用jython调用python,提示console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0. ...

  8. 教你判断一个APP页面是原生的还是H5页面 。(还没看)

    来源:https://www.25xt.com/appdesign/11851.html 刚好是周末,无意之间学堂君在收集相关资料的时候,发现有部分童鞋在问<如何判断一个APP页面是不是H5页面 ...

  9. 汇编_指令_SHL、SHR、SAL、SAR、ROL、ROR、RCL、RCR

    ;SHL(Shift Left):      逻辑左移 ;SHR(Shift Right):      逻辑右移 ;SAL(Shift Arithmetic Left): 算术左移 ;SAR(Shif ...

  10. libevent源码学习

    怎么快速学习开源库比如libevent? libevent分析 - sparkliang的专栏 - 博客频道 - CSDN.NET Libevent源码分析 - luotuo44的专栏 - 博客频道 ...