We have many options because matrix multiplication is an associative operation, meaning that the order in which we multiply does not matter. The optimal order depends only on the dimensions of the matrices.
The brute-force algorithm is to consider all possible orders and take the minimum. This is a very inefficient method.
Implement the minimum multiplication algorithm using dynamic programming.
Input Format
The input file must contain the dimensions of the matrices each on a separate line.
Constraints
Input should consist of positive integers.
Output Format
The output file must contain the minimum number of multiplications needed to multiply the matrices as an integer.
Sample Input
20
2
30
12
8
Sample Output
1232
Explanation
The above input and output samples correspond to the multiplication of these four matrices:
Input Format
The input file must contain the dimensions of the matrices each on a separate line.
Constraints
Input should consist of positive integers.
Output Format
The output file must contain the minimum number of multiplications needed to multiply the matrices as an integer.
Sample Input
Sample Output
Explanation
The above input and output samples correspond to the multiplication of these four matrices:
*A1 (20x2) A2 (2x30) A3 (30x12) A4 (12x8) note : read readme.md carefully**