Introduction to Dynamic Programming - Algorithms for Competitive Programming
The essence of dynamic programming is to avoid repeated calculation. Often, dynamic programming problems are naturally solvable by recursion. In such cases, it's easiest to write the recursive solution, then save repeated states in a lookup table. This process is known as top-down dynamic programming with memoization. That's read "memoization" (like we are writing in a memo pad) not memorization. One of the most basic, classic examples of this process is the fibonacci sequence. Its recursive formulation is 𝑓 ( 𝑛 ) = 𝑓 ( 𝑛 − 1 ) + 𝑓 ( 𝑛 − 2 ) <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo><mo>=</mo><mi>f</mi><mo stretchy="false">(</mo><mi>n</mi><mo>−</mo><mn>1</mn><mo stretchy="false">)</mo><mo>+</mo><mi>f</mi><mo stretchy="false">(</mo><mi>n</mi><mo>−</mo><mn>2</mn><mo stretchy="false">)</mo></math> $f(n) = f(n-1) + f(n-2)$ where 𝑛 ≥ 2 <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>n</mi><
Last update: August 26, 2025   Original Introduction to Dynamic Programming ¶ The essence of dynamic programming is to avoid repeated calculation. Often, dynamic programming problems are naturally solvable by recursion. In such cases, it's easiest to write the recursive solution, then save repeated states in a lookup table. This process is known as top-down dynamic programming with memoization. That's read "memoization" (like we are writing in a memo pad) not memorization. One of the most basic, classic examples of this process is the fibonacci sequence. Its recursive formulation is
Explore this link on the map →saved by
related reading
- Tabulation vs. Memoization | Baeldung on Computer Sciencebaeldung.com
- Fibonacci Numbers - Algorithms for Competitive Programmingcp-algorithms.com
- Binary Exponentiation - Algorithms for Competitive Programmingcp-algorithms.com
- Euclidean algorithm for computing the greatest common divisor - Algorithms for Competitive Programmingcp-algorithms.com
- Dynamic programming - Wikipediaen.wikipedia.org
- The complete beginners guide to dynamic programming - Stack Overflowstackoverflow.blog
- Memoization - Wikipediaen.wikipedia.org
- Competitive Programmer's Handbookcses.fi
- abseil / Performance Hintsabseil.io
- Boosting Dynamic Programming Performance Using NVIDIA Hopper GPU DPX Instructions | NVIDIA Technical Blogdeveloper.nvidia.com
- Structure and Interpretation of Computer Programsmitp-content-server.mit.edu
- Ranking Interview Questions by Cram Score | Jeremy Aguilonjeremyaguilon.me