← 返回 bytedance 的题目列表Dynamic Programming Problem
类型:online_judge
bytedance
You have a row of houses, each containing a certain amount of money. You cannot rob two adjacent houses at the same time. Design an algorithm to calculate the maximum amount of money you can rob tonight. The maximum number of houses is 100 and each house contains at most 1000 money.
Example:
Input: [1,2,3,1] Output: 4
Explanation: Rob house 1 (money = 1) and house 3 (money = 3), total = 1 + 3 = 4.
Input: [2,7,9,3,1] Output: 12
Explanation: Rob house 1 (money = 2), house 3 (money = 9) and house 5 (money = 1), total = 2 + 9 + 1 = 12.
Example
Input
[1,2,3,1]