引言 二维动态规划中最常见的是棋盘型二维动态规划. 即 func(i, j) 往往只和 func(i-1, j-1), func(i-1, j) 以及 func(i, j-1) 有关 这种情况下,时间复杂度 O(n*n),空间复杂度往往可以优化为O(n) 例题  1 Minimum Path Sum  Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whi…
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. SOLUTION 1: 相当基础…
题目: 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. 题意从左上到右下,所有可能的路径中,求经过的元素和最小值.…
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. 做这题之前,建议先看一下Leetcode Triangle 这题看…
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. 这道题跟之前那道Dungeon Game 地牢游戏 没有什么太大的…
题目链接 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[i][j]表示从左上角到g…
原题地址:https://oj.leetcode.com/problems/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 r…
题意: 给一个n*m的矩阵,每次可以往下或右走,经过的格子中的数字之和就是答案了,答案最小为多少? 思路: 比较水,只是各种空间利用率而已. 如果可以在原空间上作修改. class Solution { public: int minPathSum(vector<vector<int>>& grid) { ; ; ; j<=m; j++) grid[][j]+=grid[][j-]; ; i<=n; i++) { grid[i][]+=grid[i-][]; ;…
题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 题意给两个字符串表示的数字,计算他们的乘积. 其实就是手写一个大数乘法,先翻转字符串便于从低位开始计算. 模拟乘法的运算过程,把中间结果存在data中,最后在考虑data的进位并…
Unique Paths https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to rea…