Let
, where A_{i} has dimensions
P[i-1] x P[i]. P is an array of dimensions.

For now, the subproblems will be finding the minimum number of scalar
multiplications m[i,j] for computing
A_{i .. j}(1 i j n).

Define m[i,j].

If i = j, m[i,j] = 0 (single matrix).

If i < j, assume an optimal split between A_{k} and A_{k+1}(i
k < j).
m[i,j] = cost of computing
A_{i .. k} +
cost of computing
A_{k+1 .. j} +
cost of computing
A_{i .. k}A_{k+1 .. j}
= m[i,k] + m[k+1,j] + P[i-1]P[k]P[j]
However, we do not know the value of k, so we have to try all