【leetcode】Minimum Path Sum
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.
class Solution {
public:
int minPathSum(vector<vector<int> > &grid) {
int m=grid.size();
int n=grid[].size();
/* int **dp=new int *[m];
for(int i=0;i<m;i++)
{
dp[i]=new int[n];
}
*/
vector<vector<int>> dp(m,vector<int>(n));
dp[][]=grid[][];
for(int i=;i<m;i++)
{
dp[i][]=dp[i-][]+grid[i][];
}
for(int j=;j<n;j++)
{
dp[][j]=dp[][j-]+grid[][j];
}
for(int i=;i<m;i++)
{
for(int j=;j<n;j++)
{
dp[i][j]=grid[i][j]+min(dp[i-][j],dp[i][j-]);
}
}
return dp[m-][n-];
}
};
【leetcode】Minimum Path Sum的更多相关文章
- 【leetcode】Minimum Path Sum(easy)
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- 【题解】【矩阵】【DP】【Leetcode】Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- 【LeetCode】113. Path Sum II 解题报告(Python)
[LeetCode]113. Path Sum II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fu ...
- 【leetcode】437. Path Sum III
problem 437. Path Sum III 参考 1. Leetcode_437. Path Sum III; 完
- 【LeetCode】113. Path Sum II
Path Sum II Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals ...
- 【LeetCode】666. Path Sum IV 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 日期 题目地址:https://leetcod ...
- 【Leetcode】【Medium】Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- 【LeetCode】437. Path Sum III 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS + DFS BFS + DFS 日期 题目地 ...
- 【LeetCode】113. Path Sum II 路径总和 II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 文章目录 题目描述 题目大意 解题方法 BFS DFS 日期 题目地址:https:// ...
随机推荐
- CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL)
CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL) 一.准备篇: /etc/init.d/iptables stop #关闭防火墙 关闭SELINUX vi /etc/sel ...
- jQuery 参考手册 - 遍历
jQuery 参考手册 - 遍历 jQuery Ajax jQuery 数据 jQuery 遍历函数 jQuery 遍历函数包括了用于筛选.查找和串联元素的方法. 函数描述 .add()将元素添加到匹 ...
- TFS2012 安装 配置笔记
TFS2012安装 具体请看文档.. http://yunpan.cn/cmt4X6S7TjEgq 访问密码 464e TFS2012配置 环境:VS2012 SQL2008 T ...
- reactjs 注意点
render的return return前要留一空行 return的括号要分别各占一行,不能与html同行 return中的html必须要有顶层容器包裹 return中的循环不能用for,改用map方 ...
- 数据库创建用户SQL
', default_database=TableName use TableName create user A for login A with default_schema=dbo exec s ...
- angularjs DOM操作之jqLite篇
angular.element(el).find("input").attr({value:1}); * ## Angular's jqLite * jqLite provides ...
- the usage of linux command "expect"
#! /usr/bin/expect -f# this script is used to practise the command "expect" #when "li ...
- jQuery回调、递延对象总结(下篇) —— 解密jQuery.when方法
前言: 前一篇文章中重点总结了一下then方法,它主要用来处理多个异步任务按顺序执行,即前一个任务处理完了,再继续下一个,以此类推: 而这一章节jQuery.when方法也是处理多个异步任务,它把多个 ...
- app的meta
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> < ...
- Swift2.1 语法指南——协议
原档: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programm ...