Matrix Chain Multiplication
00:00
TCSAmazonGoogle
Find minimum number of scalar multiplications to multiply a chain of matrices. matrices[i] has dimensions p[i-1]×p[i].
Examples
Input → p=[1,2,3,4]
Output → 18
Note: optimal: A1×A2×A3 or A1×A2×A3 — try both
Input → p=[40,20,30,10,30]
Output → 26000
Input → p=[10,30,5,60]
Output → 4500