Introduction to algorithms 15.2 matrix chain Multiplication

Source: Internet
Author: User

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 )))

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.