com.dynamic; { [][]size; [][]momery; [][]s; MatrixChainMultiple( [][]size) Exception{ ( i;isize.length;i){ (size[i][]size[i][]){ Exception(); } } .sizesize; momery [size.length][size.length]; ( i;imomery.length;i){ momery[i][i]; } s [size.length][size.length]; } matrixChainOrder(){ innerMatrixChainOrder(,size.length); } innerMatrixChainOrder( i, j){ (ijmomery[i][j]){ momery[i][j]; } tmp.MAX_VALUE; ( ki;kj;k){ qinnerMatrixChainOrder(i,k)innerMatrixChainOrder(k,j)size[i][]size[k][]size[j][]; (qtmp){ tmpq; s[i][j]k; } } momery[i][j]tmp; tmp; } printSolution(){ printSolution(,size.length); } printSolution( i, j){ (ij){ System.out.print(i); }{ System.out.print(); printSolution(i,s[i][j]); printSolution(s[i][j],j); System.out.print(); } } main([] args) Exception { [][]size [][]{ {,}, {,}, {,}, {,}, {,}, {,} }; MatrixChainMultiple chain MatrixChainMultiple(size); System.out.println(chain.matrixChainOrder()); chain.printSolution(); } }