Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2

A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [12, 16, 8, 10, 7, 10], where Mi has size p[i−1] × p[i] (1-indexed). Multiplying two matrices of sizes a×b and b×c costs a·b·c scalar multiplications. What is the minimum total number of scalar multiplications over all parenthesisations?

  1. A. 3608
  2. B. 4700
  3. C. 4176
  4. D. 4320

Correct answer: A. 3608

The interval DP gives 3608. Multiplying strictly left to right costs 4176; the greedy 'cheapest adjacent pair first' rule gives 4320, which is not optimal.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic