public class Solution {
/**
* @param A: An array of non-negative integers.
* return: The maximum amount of money you can rob tonight
*/
public long houseRobber(int[] A) {
// write your code here
if(A.length==0)
return 0;
if(A.length==1){
return A[0];
}
if(A.length==2){
return Math.max(A[1], A[0]);
}
if(A.length==3){
return Math.max(A[1], A[0]+A[2]);
}
long dp[]=new long[A.length];
for(int i=0;i<A.length;i++){
if(i==0){
dp[i]=A[i];
}else if(i==1){
dp[i]=Math.max(A[0], A[1]);
}else if(i==2){
dp[i]=Math.max(A[0]+A[2], A[1]);
}else{
dp[i]=Math.max(dp[i-2], dp[i-3])+A[i];
}
}
return Math.max(dp[A.length-1], dp[A.length-2]);
}
}