# leetcode-House Robber-198（dp）

http://blog.csdn.net/AC_0_summer/article/details/52210957

dp1[i]=dp2[i-1]+nums[i]；dp2[i]=max(dp1[i-1],dp2[i-1])

class Solution {
public:
int rob(vector<int>& nums) {
int len=nums.size();
if(len==0) return 0;
if(len==1) return nums[0];
vector<int> dp1(len+1,0);
vector<int> dp2(len+1,0);
dp1[0]=nums[0];
for(int i=1;i<len;i++){
dp1[i]=dp2[i-1]+nums[i];
dp2[i]=max(dp1[i-1],dp2[i-1]);
}
return max(dp1[len-1],dp2[len-1]);
}
};

• 本文已收录于以下专栏：

## LeetCode#198. House Robber

You are a professional robber planning to rob houses along a street. Each house has a certain amount...

## LeetCode动态规划198. House Robber思路解析

LeetCode动态规划198. House Robber思路解析，用最容易理解的递归解释

## Leetcode 198. House Robber

You are a professional robber planning to rob houses along a street. Each house has a certain amount...

## Leetcode[198]-House Robber

You are a professional robber planning to rob houses along a street. Each house has a certain amount...

## LeetCode - 198. House Robber

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)