Find the optimal matrix-chain multiplication given a sequence of matrices