r/programming • • Apr 16 '19

A graphical introduction to dynamic programming

https://medium.com/@avik.das/a-graphical-introduction-to-dynamic-programming-2e981fa7ca2?source=friends_link&sk=37cd14642cf1a83eb0bb33d231442837
55 Upvotes

14 comments sorted by

View all comments

1

u/wrensdad Apr 17 '19

Either I'm stupid or the article isn't friendly enough but I couldn't understand the logic behind the house robber one. Then it started jumping to math function notation `f(n-1)` before I knew what the robber was doing and I was out.

4

u/akdas Apr 17 '19

Sorry the article wasn't clear enough. I would love to clarify. The basic idea is that you work backwards from the last house to the first. At each house, you can:

  • Steal from the house, but then you have to skip the previous house (can't steal from two houses next to each other).

  • Not steal from the house, and then you don't have to skip the previous house. You might still skip the previous house, but stealing from that house is still an option should you choose to take it.

Does that intuition help?