Matrix Chain Multiplication
Matrices have sizes . Multiplying a by a matrix costs . Find the minimum total cost to compute the whole product (choose the best bracketing).
Input
, then the dimensions .
Output
The minimum cost.
Constraints
,
Sample 1
Input
3 10 30 5 60
Output
4500
Sample 2
Input
4 40 20 30 10 30
Output
26000