### 问题描述

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 you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.

Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases. Also thanks to @ts for adding additional test cases.

### 分析

f(0) = nums
f(1) = max(f(0), nums)
f(i) = max(f(i-1), f(i-2)+nums[i])


### 代码

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