Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional

A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [11, 8, 3, 12, 16, 9], 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. 3576
  2. B. 3060
  3. C. 1569
  4. D. 4356

Correct answer: C. 1569

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic