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 j-i possibilities.

Note that a recursive algorithm based on this definition would still require exponential time.