DP visualizer
Watch the table fill cell by cell. The cells each value was built from light up, and the final traceback is drawn in accent.
- State
- Transition
- Answer
- Cost
Custom syntax
Row 0 and column 0 take the base expression; every other cell takes the transition, evaluated row by row, left to right.
Names: i, j (current cell), n, m (last row / column), dp[i-1][j] (only cells already filled; anything else reads as 0), a[i], b[j], INF.
Operators: + - * / % (integer division), comparisons, && || !, c ? x : y, functions min max abs. Nothing else is evaluated.
Example, unbounded knapsack by weight: rows = items + 1, cols = capacity + 1, base 0, transition j >= a[i-1] ? max(dp[i-1][j], dp[i][j-a[i-1]] + b[i-1]) : dp[i-1][j].
Pick a pattern and build the table.
| Row | |
|---|---|