Matrix chain order: fill the table
Warm-up · Trace the algorithm · about 6 min
Four matrices have dimensions p = [4, 2, 3, 1, 3], so A1 is 4 × 2 and A4 is 1 × 3. Follow the table of fewest multiplications. Answer each question before the step plays.
Example 1
Input:
{"values":[40,20,30,10,30]}
Output:
26
Constraints
- The trace uses the dimensions shown.
- Cell (Ai, Aj) holds the fewest multiplications for Ai … Aj.
Learn the idea first: Interval DP: matrix chain, burst balloons, palindrome partitioning, a visual lesson.
More Interval DP: matrix chain, burst balloons, palindrome partitioning problems
- Matrix chain multiplication Standard
- Burst balloons Standard
- Palindrome partitioning II Standard