The following describes an application example of dynamic programming-matrix chain multiplication.
The following is the matrix chain multiplication implemented in Java,CodeFollowAlgorithmThe introduction is strictly written. You can learn from the introduction to algorithms.
The implementation code is as follows:
package homework. part2.work1; public class matrix_chain {public int [] [] m; Public int [] [] S; public static void main (string [] ARGs) {// todo auto-generated method stubint [] array = {5, 10, 3, 12, 5, 50, 6}; matrix_chain chain = new matrix_chain (); chain. matrix_chain_order (array); chain. matrix_chain_print (chain. s, 0, array. length-2);} public void matrix_chain_order (INT [] array) {int n = array. length-1; M = new int [N] [N]; S = new int [N] [N]; for (INT I = 0; I
Using the above Code, we now provide the running result for the example in the book and the 15.2-1 exercise question.
The running result of the example in the book:
(A0 (a1a2) (a3a4) A5 ))
Result of exercise 15.2-1:
(A0a1) (a2a3) (a4a5 )))