package DynamicProgramming; // Matrix-chain Multiplication // Problem Statement // we have given a chain A1,A2,...,Ani of n matrices, where for i = 1,2,...,n, // matrix Ai has dimension pi−1 ×pi // , fully parenthesize the product A1A2 ···An in a way that // minimizes the number of scalar multiplications. public class MatrixChainRecursiveTopDownMemoisation { static int Memoized_Matrix_Chain(int p[]) { int n = p.length ; int m[][] = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { m[i][j] = Integer.MAX_VALUE; } } return Lookup_Chain(m, p, 1, n-1); } static int Lookup_Chain(int m[][],int p[],int i, int j) { if ( i == j ) { m[i][j] = 0; return m[i][j]; } if ( m[i][j] < Integer.MAX_VALUE ) { return m[i][j]; } else { for ( int k = i ; k