In this recipe, we will use a dynamic programming algorithm that finds the optimal order of multiplications. Before we proceed to how the solution is implemented, take a quick look at our brief description to check your understanding of what this algorithm does.
You can find its detailed outline at https://en.wikipedia.org/wiki/Matrix_chain_multiplication or here: Cormen, Thomas H; Leiserson, Charles E; Rivest, Ronald L; Stein, Clifford (2001): Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill. pp. 331–338. The general idea of the algorithm is the following. Assume that we want to multiply matrices . Let