Rob houses on a street. Adjacent houses have connected alarms — can't rob two adjacent houses. Return the maximum money you can rob.
At each house, decide: Rob (get nums[i] + best from 2 houses ago) or Skip (keep best from previous). Two variables suffice since we only need the previous two dp values.
Trying every set of non-adjacent houses means about 2 to the power n choices. And simply taking every other house isn't reliable, because sometimes the best plan skips two houses in a row.
At each house, you have exactly two choices. Rob it, and add its money to the best total from two houses back. Or skip it, and keep the best total from the house before. The best at each house is the larger of the two, and you only ever need the last two totals.
Best at i is the larger of skipping house i, or robbing it plus the best at i minus 2. Only the last two answers matter, so two variables are enough.
Run the animation above on your own input, or watch the 1:49 video explanation of House Robber with a dry run and Java code.