Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional

In how many ways can a product of four matrices A B C D be fully parenthesised (by choosing the order of multiplication)?

  1. A. 5
  2. B. 4
  3. C. 6
  4. D. 14

Correct answer: A. 5

The count of full parenthesisations of n matrices is the Catalan number C_(n-1), so for four matrices it is C_3 = 5. The count for C_4 = 14 corresponds to five matrices.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic