Given a sequence of matrices, find the most efficient way to multiply these matrices together. The problem is to find the minimum number of scalar multiplications needed to compute the matrix chain product. Given an array p[] where the i-th matrix has dimensions p[i-1] x p[i].
- An array
pof dimensions.
Input: p = [40, 20, 30, 10, 30]
Output: 26000
Explanation: Optimal parenthesization: (A1(A2A3))A4.