Matrix Multiplication Optimization
Given two matrices of dimensions pxq and qxr, it requires pqr scalar multiplications to compute the product of the two matrices.
Given the dimensions of
n matrices, what is the minimum number of scalar
multiplications required to compute the product of the matrices?
Each test case will consist of a line containing a single integer
indicating the number of matrices, and one line containing
an, where the
ith matrix is of dimension
Input will be terminated by a line containing a single
Output for each test case a single integer representing the minimum number of scalar multiplications required to find the product of the described matrices.
5 1 2 3 4 5 5 200 1 1 200 500 0