Thethiefhasfoundhimselfanewplaceforhisthieveryagain.Thereisonlyoneentrancetothisarea,calledthe"root."Besidestheroot,eachhousehasoneandonlyoneparenthouse.Afteratour,thesmartthiefrealizedthat"allhousesinthisplaceformsabinarytree".Itwillautomaticallycontactthe..
分类:
其他好文 时间:
2016-03-15 00:52:59
阅读次数:
366
Afterrobbingthosehousesonthatstreet,thethiefhasfoundhimselfanewplaceforhisthieverysothathewillnotgettoomuchattention.Thistime,allhousesatthisplacearearrangedinacircle.Thatmeansthefirsthouseistheneighborofthelastone.Meanwhile,thesecuritysystemforthesehousesr..
分类:
其他好文 时间:
2016-03-14 16:45:01
阅读次数:
177
题意是强盗能隔个马抢马,看如何获得的价值最高 动态规划题需要考虑状态,阶段,还有状态转移,这个可以参考《动态规划经典教程》,网上有的下的,里面有大量的经典题目讲解 dp[i]表示到第i匹马时的最大价值是多少, 因此所有的dp[i] = max(dp[i-2]+nums[i],dp[i-1]) (其中
分类:
其他好文 时间:
2016-03-01 20:35:53
阅读次数:
138
In this problem, house are arranged in a circle, robber should not invade into two adjacent houses. Compared to the former problem, we need to conside
分类:
其他好文 时间:
2016-02-29 09:18:13
阅读次数:
152
用DP思维很好解决 注意终止条件 这里添加了一个数组 length = nums.length + 1;代码:public class Solution { public int rob(int[] nums) { int[] money = new int[nums.lengt...
分类:
其他好文 时间:
2016-01-10 08:12:04
阅读次数:
206
这题,是不能连续抢两间相邻的店铺。我不知道是不是一个环,姑且算作不是一个环。 如果你已经来到了第n间店铺,那么你有两个选择。 1.抢:sum[n] = sum[n - 2] +n.value 。第n - 1不能抢 2.不抢:你的总收益来到前面一家店的收益总和sum[n] =sum[n - ...
分类:
其他好文 时间:
2015-12-14 18:28:58
阅读次数:
116
挺有意思的动态规划题目,只和i-2和i-3家的状态有关,取其中最大值public class Solution { public int rob(int[] nums) { int length = nums.length; if (length == 0) { ...
分类:
其他好文 时间:
2015-11-27 06:45:12
阅读次数:
173
After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This t...
分类:
其他好文 时间:
2015-11-15 10:50:13
阅读次数:
360
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo...
分类:
其他好文 时间:
2015-11-07 21:41:16
阅读次数:
205