Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[House Robber] explanation #104

Open
nahzz opened this issue Apr 18, 2016 · 0 comments
Open

[House Robber] explanation #104

nahzz opened this issue Apr 18, 2016 · 0 comments

Comments

@nahzz
Copy link

nahzz commented Apr 18, 2016

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant