diff --git a/Dynamic Programming/MatrixChainMultiplication.java b/Dynamic Programming/MatrixChainMultiplication.java new file mode 100644 index 00000000..b2231235 --- /dev/null +++ b/Dynamic Programming/MatrixChainMultiplication.java @@ -0,0 +1,120 @@ +import java.util.ArrayList; +import java.util.Scanner; + +public class MatrixChainMultiplicationTest { + private static Scanner scan = new Scanner(System.in); + private static ArrayList mArray = new ArrayList<>(); + private static int size; + private static int[][] m; + private static int[][] s; + private static int[] p; + + public static void main(String[] args) { + int count = 1; + while(true) { + String [] mSize = input("input size of matrix A("+count+") ( ex. 10 20 ) : "); + int col = Integer.parseInt(mSize[0]); + if (col==0) break; + int row = Integer.parseInt(mSize[1]); + + Matrix matrix = new Matrix(count, col, row); + mArray.add(matrix); + count++; + } + for(Matrix m : mArray) { + System.out.format("A(%d) = %2d x %2d\n", m.count(), m.col(), m.row()); + } + + size = mArray.size(); + m = new int[size + 1][size + 1]; + s = new int[size + 1][size + 1]; + p = new int[size + 1]; + + for (int i=0; i