more codes see:

https://github.com/lightmen/leetcode.git

int rob(int num[], int n) {

```
int *dp;
int i;
dp = (int *)malloc(sizeof(int) * (n+1));
dp[0] = 0;
dp[1] = num[0];
for(i = 2; i <= n; ++i)
dp[i] = (dp[i-1] > (dp[i-2] + num[i-1])) ?
dp[i-1] : dp[i-2] + num[i-1];
return dp[n];
```

}