#include <malloc.h>
int MAX(int x,int y){
return x>y?x:y;
}
int rob(int* nums, int numsSize) {
int *m;
int i;
m = (int *)malloc(sizeof(int)*(numsSize+1));
m[0] = 0;
m[1] = nums[0];
m[2] =MAX(nums[0],nums[1]);
for(i=3;i<=numsSize;i++){
m[i] = MAX(m[i-1],nums[i-1]+m[i-2]);
}
return m[numsSize];
}
初学dp,终于能写出一个dp水题了,也算是提升吧