#C483. House Robber Problem
House Robber Problem
House Robber Problem
You are given a list of non-negative integers representing the amount of money in each house. Your task is to determine the maximum amount of money you can rob in one night without alerting the police. The twist is that you cannot rob two adjacent houses, as this will trigger the alarms.
This problem can be solved using a dynamic programming approach. The recurrence relation is given by:
$dp[i] = \max(dp[i-1], dp[i-2] + nums[i])$
where $dp[i]$ represents the maximum money that can be robbed from the first i houses.
inputFormat
The input consists of multiple test cases. Each test case starts with an integer n (the number of houses), followed by a line containing n non-negative integers separated by spaces (the amount of money in each house). The input ends when a test case with n = 0 is encountered, which should not be processed.
outputFormat
For each test case, output the maximum amount of money that can be robbed without alerting the police. Print each result on a new line.
## sample1
5
0
5
</p>