Classic example
Input
[40, 20, 30, 10, 30]
Output
26000
There are multiple ways to parenthesize the product; the optimal ordering yields 26000 scalar multiplications.
Full lesson preview
Find the minimum number of scalar multiplications needed to multiply a chain of matrices using dynamic programming.
Problem statement
Task
Examples
Input
[40, 20, 30, 10, 30]
Output
26000
There are multiple ways to parenthesize the product; the optimal ordering yields 26000 scalar multiplications.
Input format
Output format
Constraints
Samples
Input
[10, 20, 30]
Output
6000
Only two matrices (10x20) and (20x30) => cost = 10*20*30 = 6000.