Dynamic Programming - Thief Variation Probem
For $i=1,\dots,N$, and $r \in \{S,R,B\}$
define $OPT[i,r]$ as
the maximum profit that can be obtained by robbing a suitable subset of the first $i$ houses with the following constraints:


If $x=S$  (as in Skip) then house $i$ must not be robbed.
If $x=R$ then house $i$ must be Robbed while house $i+1$ will not be robbed (to avoid a case distinction later we pretend that house $i+1$ exists even when $i=N$).
If $x=B$ then Both house $i$ and house $i+1$ need to be robbed.


For $i=1$ you have $OPT[1,S] = 0$, $OPT[1,R] = x_1$, $OPT[1,B] = y_1$.

For $i&gt;1$ you have:
$$
OPT[i, S] = \max\{ OPT[i-1, S], OPT[i-1, R] \},
$$
$$
OPT[i, R] = \max\{ x_i + OPT[i-1, S], y_i + OPT[i-1, B] \},
$$
$$
OPT[i, B] = \max\{ y_i + OPT[i-1, S], z_i + OPT[i-1, B] \}.
$$

The optimal profit is then:
$\max\{OPT[N, S], OPT[N, R] \}$ and can be computed in $O(N)$ overall time using the above formulas.