Lab 13 Dynamic Programming: Matrix Chain Multiplication Solution

$30.00

Description

Description In this assignment you are asked to implement a dynamic programming algo-rithm: matrix chain multiplication (chapter 15.2), where the goal is to nd the most computa-tionally e cient matrix order when multiplying an arbitrary number of matrices in a row. You can assume that the entire input will be given as integers that can be stored using the standard C++ int type and that matrix sizes will be at least 1.

Input The input has the following format. The rst number, n 1, in the test case will tell you how many matrices are in the sequence. The rst number will be then followed by n + 1 numbers indicating the size of the dimensions of the matrices. Recall that the given information is enough to fully specify the dimensions of the matrices to be multiplied.

Output First, you need to output the minimum number of scalar multiplications needed to multiply the given matrices. Then, print the matrix multiplication sequence, via parentheses, that minimizes the total number of number multiplications and the . for multiplication symbol. Each matrix should be named A#, where # is the matrix number starting at 0 (zero) and ending at n 1. See the examples below.

Examples of input and output

2

2 3 5

30

(A0.A1)

3

10 100 5 50

7500

((A0.A1).A2)

3

1030560

4500

((A0.A1).A2)

6

3035155102025

15125

((A0.(A1.A2)).((A3.A4).A5))


error: Content is protected !!