//---------------------------------------------------------------------------- // MatrixChainMultiplication.java // Implementation of Dynamic Programming for the Matrix-Chain Multiplication // problem. //---------------------------------------------------------------------------- class MatrixChainMultiplication{ public static void main( String[] args ){ int i, j, k, d, min, temp, min_k; //int[] p = {5, 10, 3, 12, 5, 50, 6}; // sizes of matrices in the chain int[] p = {10,20,30,10,40,10}; // sizes of matrices in the chain int n = p.length-1; // number of matrices in the chain int[][] M = new int[n+1][n+1]; // table of optimal subproblem values int[][] S = new int[n+1][n+1]; // table of optimal split points // Initialize lower triangles to 0 for(i=1; i<=n; i++){ for(j=1; j<=i; j++){ M[i][j] = 0; S[i][j] = 0; } } // Compute off diagonals (d=j-i) for(d=1; d