You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
In the explanation of 'House Robber,' you mentioned
/*
Dynamic Programming
*
We can easy find the recurive fomular:
*
dp[n] = max(
dp[n-1], // the previous house has been robbed.
dp[n-2] + money[n] // the previous house has NOT been robbed.
)
The initalization is obvious:
dp[1] = money[1]
dp[2] = max(money[1], money[2])
*/
I think its a bit misleading . Actually dp[n-1] does not mean "the previous house has been robbed". For example : given 'money' as [2,1,3,5], 'dp' would be [2,2,5,7] . As you can see dp[1]=2, therefore when you calculate dp[2], dp[1] does NOT mean the second house(index 1) has been robbed.
The correct explanation should be : dp[n] stands for 'the maximum amount of money in total you can rob so far". dp[n-1] means "if you do NOT rob the current house [n] , what you can get so far",
But still, your ideas have impressed and helped me a lot. Thanks !
The text was updated successfully, but these errors were encountered:
Hello,
In the explanation of 'House Robber,' you mentioned
/*
*
*
I think its a bit misleading . Actually dp[n-1] does not mean "the previous house has been robbed". For example : given 'money' as [2,1,3,5], 'dp' would be [2,2,5,7] . As you can see dp[1]=2, therefore when you calculate dp[2], dp[1] does NOT mean the second house(index 1) has been robbed.
The correct explanation should be : dp[n] stands for 'the maximum amount of money in total you can rob so far". dp[n-1] means "if you do NOT rob the current house [n] , what you can get so far",
But still, your ideas have impressed and helped me a lot. Thanks !
The text was updated successfully, but these errors were encountered: