码迷,mamicode.com
首页 >  
搜索关键字:robber    ( 302个结果
Housse Robber II | leetcode
可以复用house robber的代码,两趟dp作为两种情况考虑,选最大值#include #define MAX 1000#define max(a,b) ( (a)>(b)?(a):(b) )int dp[MAX]={0};int rob1(int* a, int n) { int i; ...
分类:其他好文   时间:2015-05-30 19:47:09    阅读次数:112
LeetCode 198. House Robber
动态规划,构造dp[n][2]数组, dp[i][0]: 在不取nums[i]的情况下,从nums[0, 1, ..., n]中能获得的最大值; dp[i][1]: 在取nums[i]的情况下,从nums[0], 1, ..., n]中能获得的最大值。 注意到,max(dp[i][0], dp[i][1])表征了从nums[0, 1, ..., n]中获得的最大值。 初始化: dp[0][0] = 0; dp[0][1] = nums[1]. 状态方程: dp[i][0] = max(dp[i-1][0...
分类:其他好文   时间:2015-05-30 16:43:39    阅读次数:108
leetCode | House Robber
简单的动态规划状态方程:dp[i]=max{dp[i-1],dp[i-2]+a[i]}.//其实就是分为选择a[i]和不选择a[i]两种情况,取最大值。代码如下:#define MAX 1000#define max(a,b) ( (a)>(b)?(a):(b) )int dp[MAX]={0};i...
分类:其他好文   时间:2015-05-30 16:28:26    阅读次数:92
LeetCode198 House Robber
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-05-30 01:48:23    阅读次数:101
House Robber II
House Robber II问题:Note:This is an extension ofHouse Robber.After robbing those houses on that street, the thief has found himself a new place for his ...
分类:其他好文   时间:2015-05-28 00:42:45    阅读次数:158
House Robber I && II
IYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping y...
分类:其他好文   时间:2015-05-27 06:17:38    阅读次数:105
[LeetCode] House Robber II
House Robber II Note: This is an extension of House Robber. 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...
分类:其他好文   时间:2015-05-23 00:07:43    阅读次数:136
LeetCode House Robber II
LeetCode House Robber II题目思路思路来源于Discuss。 一是在Robber这题中的O(n)解法; 二是在Robber这题中,我们只需要分别考虑包含了nums[0]和nums[n-1]的情况即可。 注意这里的包含并不是说Robber一定要偷num[0]或nums[n-1],只是说考虑进去的意思。代码#define max(a, b) ((a)>(b)?(a):(b))...
分类:其他好文   时间:2015-05-21 09:06:49    阅读次数:155
leetcode 213 : House Robber II
leetcode 213 : House Robber II...
分类:其他好文   时间:2015-05-21 07:50:58    阅读次数:115
[LeetCode] House Robber II 打家劫舍之二
Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that...
分类:其他好文   时间:2015-05-21 06:35:47    阅读次数:114
302条   上一页 1 ... 22 23 24 25 26 ... 31 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!