Dynamic Programming or DP Last Updated : 25 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Dynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of subproblems so that we do not have to re-compute them when needed later. This simple optimization typically reduces time complexities from exponential to polynomial. Some popular problems solved using Dynamic Programming are Fibonacci Numbers, Diff Utility (Longest Common Subsequence), Bellman–Ford Shortest Path, Floyd Warshall, Edit Distance and Matrix Chain Multiplication.Basic of DPIntroduction to DP Tabulation vs MemoizationSteps to solve a DP ProblemBasic ProblemsFibonacci numbersTribonacci NumbersLucas NumbersClimbing StairsClimbing Stairs with 3 MovesWeighted Climbing Stairs Maximum Segments nth Catalan NumberCount Unique BSTsCount Valid ParenthesisWays to Triangulate a PolygonMin Sum in a TriangleMinimum Perfect SquaresWays to Partition a SetBinomial CoefficientPascal's TriangleNth Row of Pascal TriangleMin Sum in a TriangleEasy Problems House RobberMin Cost PathDecode WaysSubset Sum ProblemCoin change problem - Count Ways Coin Change – Minimum Coins to Make SumPainting Fence AlgorithmCutting a RodJump GameLongest Common SubstringCount all paths in a GridPaths in a Grid with ObstaclesPermutations with K Inversions Max A's using Special KeyboardMedium Problems Water Overflow Longest Common Subsequence Longest Increasing SubsequenceEdit DistanceLargest Divisible SubsetWeighted Job Schedulling0-1 Knapsack ProblemPrinting Items in 0/1 KnapsackUnbounded KnapsackWord Break ProblemTile Stacking ProblemBox-Stacking ProblemPartition ProblemLongest Palindromic SubsequenceLongest Common Increasing Subsequence (LCS + LIS)All distinct subset (or subsequence) sumsCount DerangementsMinimum insertions for palindromeWildcard Pattern MatchingRegular Expression MatchingArrange Balls with adjacent of different typesLongest Subsequence with 1 adjacent differenceMaximum size square sub-matrix with all 1sBellman–Ford AlgorithmFloyd Warshall Algorithm Maximum Tip CalculatorHard Problems Largest X Bordered SquareEgg Dropping ProblemPalindrome PartitioningPalindromic Substring CountWord Wrap ProblemOptimal Strategy for a GameThe painter’s partition problemProgram for Bridge and Torch problemMatrix Chain MultiplicationPrinting Matrix Chain MultiplicationMaximum sum rectangleStock Buy and Sell - At-Most k TimesStock Buy and Sell - At Most 2 TimesMin cost to sort strings using ReversalsCount of AP SubsequencesDP on TreesMax Height of Tree when any Node can be RootLongest repeating and non-overlapping substringPalindrome Substrings CountDP Problems Sorted by Topic / Dimensions / Standard ProblemsDP Standard Problems and Variations.DP Problems Dimension Wise (1D, 2D and 3D)DP Problems Topic WiseAdvanced Concepts in Dynamic Programming (DP)Bitmasking and Dynamic Programming | Set 1Bitmasking and Dynamic Programming | Set-2 (TSP)Digit DP | IntroductionSum over Subsets | Dynamic ProgrammingQuick Links:Learn Data Structure and Algorithms | DSA TutorialTop 20 Dynamic Programming Interview Questions‘Practice Problems’ on Dynamic Programming‘Quiz’ on Dynamic Programming Introduction to DP Visit Course Introduction to DP Dynamic Programming - Memoization Dynamic Programming - Tabulation Comment More infoAdvertise with us H harendrakumar123 Follow Improve Article Tags : Competitive Programming Similar Reads Complete CP GuideCompetitive Programming - A Complete GuideCompetitive Programming is a mental sport that enables you to code a given problem under provided constraints. The purpose of this article is to guide every individual possessing a desire to excel in this sport. This article provides a detailed syllabus for Competitive Programming designed by indust5 min readBasicsDSA TutorialData structures manage how data is stored and accessed, while Algorithms focus on processing this data. Examples of data structures are Array, Linked List, Tree and Heap, and examples of algorithms are Binary Search, Quick Sort and Merge Sort. Why to Learn DSA?Foundation for almost every software li7 min readMaths for DSAMaths is a fundamental component of learning Data Structure and Algorithms, just like in programming. Maths is primarily used to evaluate the effectiveness of different algorithms. However, there are situations when the answer requires some mathematical understanding or the problem has mathematical15+ min readMathematical AlgorithmsThe following is the list of mathematical coding problem ordered topic wise. Please refer Mathematical Algorithms (Difficulty Wise) for the difficulty wise list of problems. GCD and LCM: GCD of Two Numbers LCM of Two Numbers LCM of array GCD of array Basic and Extended Euclidean Steinâs Algorithm fo5 min readBit manipulationBit Manipulation for Competitive ProgrammingBit manipulation is a technique in competitive programming that involves the manipulation of individual bits in binary representations of numbers. It is a valuable technique in competitive programming because it allows you to solve problems efficiently, often reducing time complexity and memory usag15+ min readBit Tricks for Competitive ProgrammingIn competitive programming or in general, some problems seem difficult but can be solved very easily with little concepts of bit magic. We have discussed some tricks below in the previous post.Bitwise Hacks for Competitive Programming One-Liner Hacks of Bit Manipulation:One-Liner CodeFunctionx&17 min readBitwise Hacks for Competitive ProgrammingPrerequisite: It is recommended to refer Interesting facts about Bitwise Operators How to set a bit in the number 'num': If we want to set a bit at nth position in the number 'num', it can be done using the 'OR' operator( | ).  First, we left shift '1' to n position via (1<<n)Then, use the 'O14 min readDP for CPDynamic Programming (DP) IntroductionDynamic Programming is a commonly used algorithmic technique used to optimize recursive solutions when same subproblems are called again.The core idea behind DP is to store solutions to subproblems so that each is solved only once. To solve DP problems, we first write a recursive solution in a way t15+ min readDynamic Programming or DPDynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of3 min readDP on Trees for Competitive ProgrammingDynamic Programming (DP) on trees is a powerful algorithmic technique commonly used in competitive programming. It involves solving various tree-related problems by efficiently calculating and storing intermediate results to optimize time complexity. By using the tree structure, DP on trees allows p15+ min readDynamic Programming in Game Theory for Competitive ProgrammingIn the fast-paced world of competitive programming, mastering dynamic programming in game theory is the key to solving complex strategic challenges. This article explores how dynamic programming in game theory can enhance your problem-solving skills and strategic insights, giving you a competitive e15+ min readAdvancedGraph AlgorithmsGraph is a non-linear data structure like tree data structure. The limitation of tree is, it can only represent hierarchical data. For situations where nodes or vertices are randomly connected with each other other, we use Graph. Example situations where we use graph data structure are, a social net3 min readSegment TreeSegment Tree is a data structure that allows efficient querying and updating of intervals or segments of an array. It is particularly useful for problems involving range queries, such as finding the sum, minimum, maximum, or any other operation over a specific range of elements in an array. The tree3 min readBinary Indexed Tree or Fenwick TreeBinary Indexed Trees are used for problems where we have following types of multiple operations on a fixed sized.Prefix Operation (Sum, Product, XOR, OR, etc). Note that range operations can also be solved using prefix. For example, range sum from index L to R is prefix sum till R (included minus pr15 min readArray Range QueriesThe array range query problem can be defined as follows: Given an array of numbers, the array range query problem is to build a data structure that can efficiently answer queries of a particular type mentioned in terms of an interval of the indices. The specific query can be of type - maximum elemen3 min read Like