-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
下降路径最小和-931 #108
Labels
Comments
内存击败100%
|
function getMinsum(sum, arr){ |
不错的思路 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
给定一个方形整数数组 A,我们想要得到通过 A 的下降路径的最小和。
下降路径可以从第一行中的任何元素开始,并从每一行中选择一个元素。在下一行选择的元素和当前行所选元素最多相隔一列。
示例:
提示:
1 <= A.length == A[0].length <= 100
-100 <= A[i][j] <= 100
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/minimum-falling-path-sum
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
思路
题目列出了所有的下降路径,所以一开始有些误导到我去用了递归回溯法暴力求解,果不其然超时了。
其实应该用动态思路,从下往上求解,某一个格子的向下最小路径确定以后,上一行就可以直接利用下一行中这个格子的最小路径去继续求解了。
状态转移方程:
dp[i][j] = min(dp[i + 1][j - 1], dp[i + 1][j], dp[i + 1][j + 1])
The text was updated successfully, but these errors were encountered: