代码实现:
思路:打家劫舍题
int massage(int *nums, int numsSize) {if (nums == NULL || numsSize == 0) {return 0;}if (numsSize == 1) {return nums[0];}int dp[numsSize];memset(dp, 0, sizeof(dp));dp[0] = nums[0];dp[1] = (nums[0] < nums[1] ? nums[1] : nums[0]);for(int i = 2; i < numsSize; i++){dp[i] = (dp[i - 1] > (dp[i - 2] + nums[i]) ? dp[i - 1] : (dp[i - 2] + nums[i]));}return dp[numsSize - 1]; }