[{"data":1,"prerenderedAt":97},["ShallowReactive",2],{"page-blog-\u002Fblog\u002Fmy_thoughts_on_dp":3},{"id":4,"title":5,"body":6,"date_created":86,"date_modified":87,"description":88,"extension":89,"featured":90,"head":87,"meta":91,"navigation":90,"ogImage":87,"path":92,"robots":87,"schemaOrg":87,"seo":93,"sitemap":94,"stem":95,"__hash__":96},"content\u002Fblog\u002Fmy_thoughts_on_dp.md","DP",{"type":7,"value":8,"toc":82},"minimark",[9,13,16,35,44,51,54,78],[10,11,12],"p",{},"Dynamic programming is nothing but solving a bigger problem by dividing it into sub tasks and avoiding repitions in those subproblems, storing those  and building the answer from the smaller problems we solved beforehand",[10,14,15],{},"Its simple to think of",[17,18,19,23,26,29,32],"ul",{},[20,21,22],"li",{},"Split the problem into overlapping subproblems(one related to the other)",[20,24,25],{},"Solve each problem recursively(means break it into further sub problems, this is it most of the times it may not be recursive at all times)",[20,27,28],{},"Combine the solutions to the subproblems into one for the given problem",[20,30,31],{},"Important rule is that you dont compute the same problem twice because we already have it",[20,33,34],{},"Do remember that we memorize the answers we had gotten i.e, storing them",[36,37,38],"blockquote",{},[10,39,40],{},[41,42,43],"strong",{},"From what i can understand DP can be mainly classified into 5-6 types(it can be more or less, its just my preferred number)",[36,45,46],{},[10,47,48],{},[41,49,50],{},"1-D DP",[10,52,53],{},"Which is like number of ways to write a number using another set of numbers or find the longest increasing or decreasing subsequence something like that i believe, because all these can be done using a single array  of n elements and with optimal time complexities",[17,55,56],{},[20,57,58,59,62,63,67,68,67,71,74,75,77],{},"how to solve them? lets go in",[60,61],"br",{},"For the first one we can do this in O(n) time complexity, the given numbers will be very like like represent x in terms of 1, 3 and 4  we can construct this from base case as number of ways to write 1 is 1 way, like wise nubmer of ways to write 2 using 1 is 1 then we sorted the base case then from this point we can just add no.ofways",[64,65,66],"span",{},"x-1","+no.ofways",[64,69,70],{},"x-3",[64,72,73],{},"n-4"," like this i believe simpe enough to do",[60,76],{},"For the second problem we can do like have an array as a base case where we just have 1 as the longest subsequence as that is the minimum we can have then we will run a double loop to update the values each time we enconter a smaller value we see then output the maxumum value in the array simple.",[79,80,81],"style",{},"\n  body { font-size: 0.9em; } \n",{"title":83,"searchDepth":84,"depth":84,"links":85},"",2,[],"2026-08-11T12:00:00Z",null,"dynamic programming","md",true,{},"\u002Fblog\u002Fmy_thoughts_on_dp",{"title":5,"description":88},{"loc":92},"blog\u002Fmy_thoughts_on_dp","P1ukIW65VmXUGjdhYmrqYicSXAeCJV9zQqeQwdq5FM4",1786455577413]