Posts

The Trick to DP

The term Dynamic Programming was tossed by ___.  Anyway moving forward to DP tricks, reaching a recursive solution to a problem is fairly easy. One gets stuck in applying DP to it or making it iterative. Let's understand it with examples. Any recursive solution may look like this def my_recursive_function(self, input, variables) -> int: #terminating condition #recursive call 1 #recursive call 2 #..... #calculating results #returning the final result     Now variables in any recursive call are of two types State variable Non-state variables State Variables : variables that are directly involved in defining or identifying the subproblem. Or in other words, variables which are division factors in dividing a problem into subproblem. Let's be more real and consider the division of India by britishers. What was the division factor? Religion! religion divided the whole india into two. In a similar way for example:  in the ...