198.打家劫舍
简单dp。状态转移方程:dp[i] = max(dp[i-2] + nums[i], dp[i-1]);
class Solution { public: int rob(vector<int>& nums) { int len = nums.size(); if(len == 0) return 0;int dp[len] = {0}; for(int i = 0; i < len; i++) { dp[i] = nums[i]; } int max_sum = 0; dp[1] = dp[1] > dp[0] ? dp[1] : dp[0]; for(int i = 2; i < len; i++) { dp[i] = max(dp[i-2] + nums[i], dp[i-1]); } return dp[len-1]; } };