
dp
文章平均质量分 83
831143
这个作者很懒,什么都没留下…
展开
-
文章标题
天平poj1837 转载请注明出处:優YoU http://user.qzone.qq.com/289065406/blog/1299341345 提示:动态规划,01背包 初看此题第一个冲动就是穷举。。。。不过再细想肯定行不通= =O(20^20)等着超时吧。。。 我也是看了前辈的意见才联想到01背包,用动态规划来解题目大意: 有一个天平,天平左右两边各有若干个钩子,转载 2017-05-21 15:57:19 · 208 阅读 · 0 评论 -
jumpgame
动态规划经典题目 用“局部最优和全局最优解法”。我们维护一个到目前为止能跳到的最远距离,以及从当前一步出发能跳到的最远距离。局部最优local=A[i]+i,而全局最优则是global=Math.max(global, local)。递推式出来了,代码就比较容易实现了。因为只需要一次遍历时间复杂度是O(n),而空间上是O(1)。代码如下: includeincludeincludeincludei原创 2017-06-17 14:51:35 · 208 阅读 · 0 评论 -
LeetCode53——Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation: [...原创 2018-05-16 20:09:17 · 289 阅读 · 0 评论