Dynamic programming · 6 / 15 Exercise Medium

The house robber

Objective

A street has houses with money and you cannot rob two adjacent houses. At each house you decide: rob it (adding to what you had two houses back) or skip it (keeping what you had). It is dynamic programming with just two values of memory.

Instructions

  • Read a line with the money in each house (non-negative integers).
  • Show Maximum loot: x with the maximum that can be obtained.
Input
2 7 9 3 1
Output
Maximum loot: 12

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise