Leetcode 64. Minimum Path Sum 最小路径和 解题报告
来源:互联网 发布:工控机软件开发 编辑:程序博客网 时间:2024/05/18 21:43
1 解题思想
嗯,我做的时候是乱序,写的时候才发现,这完全就是和62 63一个德行啊,做法还是基本一样,不同的是,62 63是求和,64这里是取每一步的最小和。
标准的动态规划,至于怎么走,请看62 63:
Unique Paths 路径搜寻 解题报告
Unique Paths II 路径搜寻2 解题报告
2 原题
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.
3 AC解
public class Solution { /** * 很标准的动态规划的题目 * */ public int minPathSum(int[][] grid) { if(grid.length==0 || grid[0].length==0) return 0; int m=grid.length; int n=grid[0].length; int dp[][]=new int[m][n]; int top,left; int i=0,j; dp[0][0]=grid[0][0]; for( j=1;j<n;j++){ dp[i][j]=dp[i][j-1]+grid[i][j]; } for( j=1;j<m;j++){ dp[j][i]=dp[j-1][i]+grid[j][i]; } for( i=1;i<m;i++){ for( j=1;j<n;j++){ top=Integer.MAX_VALUE; left=Integer.MAX_VALUE; top=dp[i-1][j]; left=dp[i][j-1]; dp[i][j]=Math.min(top,left)+grid[i][j]; } } return dp[m-1][n-1]; }}
0 0
- Leetcode 64. Minimum Path Sum 最小路径和 解题报告
- [leetcode] 64. Minimum Path Sum 解题报告
- LeetCode 64. Minimum Path Sum 解题报告
- [Leetcode] 64. Minimum Path Sum 解题报告
- LeetCode 64. Minimum Path Sum 解题报告
- Leetcode 64. Minimum Path Sum 解题报告
- [leetcode]Minimum Path Sum 最小路径和
- Leetcode:Minimum Path Sum 最小路径和
- LeetCode 64. Minimum Path Sum(最小路径和)
- leetcode 64. Minimum Path Sum-最小路径和|动态规划
- [LeetCode]Minimum Path Sum,解题报告
- 【LeetCode】Minimum Path Sum 解题报告
- [LeetCode] Minimum Path Sum 解题报告
- LeetCode | Minimum Path Sum(最小路径和)
- LeetCode OJ 之 Minimum Path Sum (最小路径和)
- [Leetcode-64]Minimum Path Sum 二维数组路径最小和
- LeetCode--Minimum Path Sum (最小路径和)Python
- Leetcode 112. Path Sum 路径和 解题报告
- js的for,if写在函数外
- 线性表和链表的区别
- GCC常用命令详解
- Tricky Priority Queue
- GCC常用命令选项
- Leetcode 64. Minimum Path Sum 最小路径和 解题报告
- html and css-task1
- java 读取 Excel文件
- php实习tips(正则表达式)
- 基本排序(包括插入,选择,冒泡排序)
- CodeChef PRIMEDSTPrime Distance On Tree
- hdu4605 Magic Ball Game(树状数组)
- Linux LVS+Keepalived负载均衡安装配置笔记
- PAT-B 1041. 考试座位号