@@ -0,0 +1,1268 @@
+public class MatrixChainMultiplication %7B%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(solve(new int%5B%5D %7B 6, 4, 30, 2, 10, 5 %7D));%0A    %7D%0A%0A    public static int solve(int%5B%5D matrices) %7B%0A        int length = matrices.length;%0A        int%5B%5D%5B%5D dp = new int%5Blength%5D%5Blength%5D;%0A%0A        for (int i = 0; i %3C length; i ++) %7B%0A            for (int j = 0; j %3C length; j ++) %7B%0A                dp%5Bi%5D%5Bj%5D = i == j ? 0 : Integer.MAX_VALUE;%0A            %7D%0A        %7D%0A%0A        for (int jump = 1; jump %3C length - 1; jump ++) %7B%0A            for (int i = 1; i + jump %3C length; i ++) %7B%0A                int j = i + jump;%0A                int product = matrices%5Bi - 1%5D * matrices%5Bj%5D;%0A                for (int k = i; k %3C j; k ++) %7B%0A                    dp%5Bi%5D%5Bj%5D = Math.min(dp%5Bi%5D%5Bj%5D, dp%5Bi%5D%5Bk%5D + dp%5Bk + 1%5D%5Bj%5D + (product * matrices%5Bk%5D));%0A                %7D%0A            %7D%0A        %7D%0A%0A        for (int i = 0; i %3C length; i ++) %7B%0A            for (int j = 0; j %3C length; j ++) %7B%0A                if (dp%5Bi%5D%5Bj%5D == Integer.MAX_VALUE) %7B%0A                    System.out.print(%22-%5Ct%22);%0A                %7D else %7B%0A                    System.out.print(dp%5Bi%5D%5Bj%5D + %22%5Ct%22);%0A                %7D%0A            %7D%0A            System.out.println(%22%22);%0A        %7D%0A%0A        return dp%5B1%5D%5Blength - 1%5D;%0A        %0A    %7D%0A%7D%0A

Add matrix chain multiplication algorithm