Skip to main content

Dynamic Programming

📄️ Guidelines

Before trying to solve a problem with DP approach first ask yourself if the problem respects the rule of optimality. To determine that see if you can solve the problem by first solving a simpler problem and then using that calculation to solve the initial one. There has to be a natural transition from smaller to larger subproblem (solving a problem for a subarray 0..2, and then using that to solve the problem for subarray 0..5). "Left to right" data structures like arrays, strings, leaves of a tree are natural candidates to apply DP approach to.