src/com/michaelho/DynamicProgramming/DP2.java
/**
     * The dynamic programming used to calculate chain multiply matrix problems. Note
     * that the calculation merely focuses on how to decide which order to perform the
     * multiplication. The runtime is O(N^3) where N is the number of matrices. Example
     * input like {10, 20, 30, 40}, which stands for 3 matrices 10x20, 20x30 and 30x40.
     *
     * @param m The array of matrix, refer to the description above for the expressions.
     * @param i The start of the serial calculation.
     * @param j The tail of the serial calculation.
     * @return The result of the minimum cost calculation.
     * */
The dynamic programming used to calculate chain multiply matrix problems. Note
that the calculation merely focuses on how to decide which order to perform the
multiplication. The runtime is O(N^3) where N is the number of matrices.

@param m The array of matrix, refer to the description above for the expressions.
@param i The start of the serial calculation.
@param j The tail of the serial calculation.
@return The result of the minimum cost calculation.
The dynamic programming used to calculate chain multiply matrix problems . Note that the calculation merely focuses on how to decide which order to perform the multiplication . The runtime is O ( N^3 ) where N is the number of matrices . @param m The array of matrix refer to the description above for the expressions . @param i The start of the serial calculation . @param j The tail of the serial calculation . @return The result of the minimum cost calculation .
int chainMatrixMultiply(int[] m, int i, int j) {
        if (i == j)
            return 0;
        int min = Integer.MAX_VALUE;
        for (int l = i; l < j; l ++) {
            int count = chainMatrixMultiply(m, i, l) +
                        chainMatrixMultiply(m, l+1, j) +
                        m[i-1]*m[l]*m[j];
            min = Math.min(min, count);
        }
        return min;
    }
int chainMatrixMultiply ( int [ ] m , int i , int j ) { if ( i == j ) return 0 ; int min = Integer . MAX_VALUE ; for ( int l = i ; l < j ; l ++ ) { int count = chainMatrixMultiply ( m , i , l ) + chainMatrixMultiply ( m , l + 1 , j ) + m [ i - 1 ] * m [ l ] * m [ j ] ; min = Math . min ( min , count ) ; } return min ; }
The dynamic programming used to calculate chain multiply matrix problems.
The dynamic programming used to calculate chain multiply matrix problems .