Skip to content

Dynamic programming [mp]

Micro pattern

Description

Define reusable states and transitions so overlapping subproblems are solved once in dependency order.

Problems

Constant-space linear DP

Keep only the few preceding scalar states needed by each transition.

One-dimensional table

Store states along one dimension and update them in dependency order.

Two-dimensional matching table

Represent relationships between prefixes of two structured sequences.

Precomputed feasibility table

Fill a table of valid ranges before using those ranges in search.

Cache recursive suffix results so repeated decompositions reuse them.

Interval DP

Solve shorter intervals before combining them into longer ones.

Tree DP

Combine reusable child summaries at each parent.

Indexed subsequence states

Track the best length or number of ways ending at each position or derived key.

Capacity-constrained states

Update amount or resource-capacity states according to item reuse rules.

Graph-path states

Propagate per-path summaries through a DAG in topological order.