I decided that we'd tackle a slightly easier problem first: Given matrices A1, A2, ..., An, what is the fewest multiplications required to compute the product of the Ai's? We devised a terribly inefficient recursive algorithm that solved this problem. Here's an implementation of that algorithm. Note that it relies on the file Matrix.h.