
```cpp
class Solution {
public:
    int rob(vector<int>& nums) {
        if(nums.size()==1)
            return nums[0];

        int res = max(nums[0], nums[1]);
        vector<int> sav(nums.size(), 0);
        sav[0] = nums[0];
        sav[1] = res;
        for(int i=2;i<nums.size();i++){
            sav[i] = max(sav[i-1], sav[i-2]+nums[i]); 
            res = max(res, sav[i]);
        }
        return res;
    }
};
```

- 1차원 dp


