Skip to content
  • Dashboard
  • Review
  • Go: plan & chat
  • Roadmap
  • Patterns & lessons49
  • Sheets
  • Problems1.5k
  • Ascend
  • Toolkit
  • Core CS + SQL
  • System Design
  • Machine Coding
  • Interview hub
  • Mock interview
  • Companies & OA
  • Leaderboard
  • Battles
  • College Cup
  • People

Keep your progress

Sync across devices with a free account.

Sign upSign in
Patterns & lessons
Sign inSign up
Patterns/Dynamic Programming/Interval DP

Technique

Knuth's Optimisation

For interval DP dp[i][j] = min_k dp[i][k] + dp[k+1][j] + C(i, j) where opt(i, j-1) <= opt(i, j) <= opt(i+1, j), restrict k to that window for O(n2).

Learn firstInterval DP
0%
mastery
0/1 solved
Practise nextKnuth Division
IdeaPracticePitfalls

Recognise it

The signal

merge/split costs on a line (optimal BST, stick cutting, file merging)

  1. 1Brute force

    O(n3) interval DP.

  2. 2The observation

    Scanning all splits: the optimal split is monotone in both endpoints.

  3. 3Why it works

    opt(i, j-1) <= opt(i, j) <= opt(i+1, j).

Reach for it when

  • +C satisfies quadrangle inequality and monotonicity

Not when

  • ×cost violates the conditions (verify or stress test)

Practice

Next

Knuth Division

0/1 solved
  • Knuth DivisionCSESHard

Pitfalls

Misconceptions

  • !applying it to burst-balloons-style DPs whose structure differs
Go deeperresources

Resources

  • DP lecture notesErrichto · video
  • AtCoder Educational DP ContestAtCoder · sheet
  • Introduction to DPUSACO Guide · course
  • Dynamic Programming PatternsLeetCode discuss · article
  • Dynamic Programming playlistAditya Verma · video
  • Bitmask DPUSACO Guide · course
  • Digit DPCodeforces · blog
TodayReviewPatternsProblems