```
int rob(vector<int>& a) {
if(a.empty())
return 0;
int n = a.size();
int dp[n];
dp[0] = a[0];
dp[1] = max(a[0],a[1]);
for(int i = 2; i < n; i++){
dp[i] = max(a[i] + dp[i-2], dp[i-1]);
}
return dp[n-1];
}
```