Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band

A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [20, 17, 5, 11, 19, 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. 6645
  2. B. 13780
  3. C. 18548
  4. D. 14580

Correct answer: A. 6645

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic