代码实现:
int rob(int *nums, int numsSize) {if (numsSize == 1) {return nums[0];}if (numsSize == 2) {return fmax(nums[0], nums[1]);}int dp[numsSize];dp[0] = nums[0];dp[1] = fmax(nums[0], nums[1]);for (int i = 2; i < numsSize; i++) {dp[i] = fmax(dp[i - 1], dp[i - 2] + nums[i]);}return dp[numsSize - 1]; }