By using Dynamic Programming, we can get the maximum amount of money step by step.

For every house along the street, there are two situations,

**1. If the previous house had been robbed, we can't rob the current house,**

```
currentMaxValue = max(previousNoRobbery, previousYesRobbery);
```

**2. If the previous house hadn't been robbed, we can rob the current house,**

```
currentMaxValue = moneyOfCurrentHouse + previousNoRobbery
```

Here's the code:

```
int rob(vector<int> &num) {
int preNoRob = 0, preYesRob = 0;
for(int i = 1; i <= num.size(); ++i) {
int preNoRobTemp = preNoRob;
preNoRob = max(preNoRob, preYesRob); // situation 1
preYesRob = num[i-1] + preNoRobTemp; // situation 2
}
return max(preNoRob, preYesRob);
}
```