Problem: Find optimal parenthesization of a chain of matrices to be multiplied such that the number of scalar multiplications is minimized.
Recall matrix multiplication algorithm:
MatrixMultiply(A,B) for i = 1 to rows(A) for j = 1 to cols(B) C[i,j] = 0 for k = 1 to cols(A) C[i,j] = C[i,j] + A[i,k] * B[k,j]
Thus the number of multiplications is p*q*r.