Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2

A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [20, 15, 18, 8, 2, 3, 20], 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. 14720
  2. B. 3390
  3. C. 2348
  4. D. 9920

Correct answer: C. 2348

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic