You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.
你是一個專業的盜賊,正在計畫偷竊一條街上的房子。每棟房子都有一定數量的金錢,唯一會限制你行動的是鄰近房子的安全系統連線,如果你在同一個夜晚闖入兩棟鄰近的房子,它就會自動聯絡警察。
給予你一個列表的非負整數代表每棟房子的金錢,請計算出你一個夜晚最高可以偷到的金額且不會觸動警察。
N棟房子的時候,你有偷或不偷的決定:
DP[N] = DP[N - 2] + money[N]DP[N] = DP[N - 1]N棟的最高金額。LeetCode C++