# Dynamic Programming

> Source: https://modeladay.com/models/dynamic-programming/
> Category: principle | Topics: decision, systems, cognition | Difficulty: 3/5

## Definition

Dynamic programming represents recurring subproblems as states and defines which smaller states determine the current one. Solve base cases first and follow the dependencies, or save results during recursion to avoid repeated work.

## Core Rule

Dynamic programming represents recurring subproblems as states and defines which smaller states determine the current one. Solve base cases first and follow the dependencies, or save results during recursion to avoid repeated work.

## Opening Context

Say you're planning three hours of afternoon talks. Twenty proposals come in, each with a length and a count of audience votes. You want the talks that fit the time and add up to the most votes.

Try making a few schedules on paper and you see the trouble. Each talk can go in or stay out, so there are over a million combinations. How many of those do you want to check by hand?

Dynamic programming solves a smaller problem once and keeps the answer for each time it comes up again. Let's take it through that afternoon schedule, then see what happens when the table leaves something important out.

## How It Works (Preview)

In the nineteen fifties, American mathematician Richard Bellman developed the idea behind the table. If a route is best all the way through, the rest of it should also be best from the point you've reached.

Think of reaching a crossroads and asking how far it is to the station. The answer is ten minutes whether you came from the east or west. Once you're there, you can work out the best way to finish from where you stand.

## When It Fails (Preview)

The trouble comes when two schedules seem to reach the same spot and actually don't. Leave out a restriction, and even a carefully filled table can give you the wrong schedule.

## Full Lesson, Audio & Practice

Get the full Dynamic Programming breakdown, 5-minute audio lesson, interactive mechanism animation, and decision checklist in the ConceptFlow app:
- iOS App Store: https://apps.apple.com/app/conceptflow-mental-models/id6756862333
- Google Play: https://play.google.com/store/apps/details?id=com.juxianyp.conceptflow
- Web page: https://modeladay.com/models/dynamic-programming/

## Related Mental Models

- [Divide and Conquer](https://modeladay.com/models/divide-and-conquer/)
- [Greedy Choice](https://modeladay.com/models/greedy-choice/)
- [Markov Chain](https://modeladay.com/models/markov-chain/)
