mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-23 04:20:16 +08:00
Refactor Code Style (#4151)
This commit is contained in:
@ -8,9 +8,9 @@ package com.thealgorithms.dynamicprogramming;
|
||||
// minimizes the number of scalar multiplications.
|
||||
public class MatrixChainRecursiveTopDownMemoisation {
|
||||
|
||||
static int Memoized_Matrix_Chain(int p[]) {
|
||||
static int Memoized_Matrix_Chain(int[] p) {
|
||||
int n = p.length;
|
||||
int m[][] = new int[n][n];
|
||||
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;
|
||||
@ -19,7 +19,7 @@ public class MatrixChainRecursiveTopDownMemoisation {
|
||||
return Lookup_Chain(m, p, 1, n - 1);
|
||||
}
|
||||
|
||||
static int Lookup_Chain(int m[][], int p[], int i, int j) {
|
||||
static int Lookup_Chain(int[][] m, int[] p, int i, int j) {
|
||||
if (i == j) {
|
||||
m[i][j] = 0;
|
||||
return m[i][j];
|
||||
@ -43,7 +43,7 @@ public class MatrixChainRecursiveTopDownMemoisation {
|
||||
// in this code we are taking the example of 4 matrixes whose orders are 1x2,2x3,3x4,4x5 respectively
|
||||
// output should be Minimum number of multiplications is 38
|
||||
public static void main(String[] args) {
|
||||
int arr[] = { 1, 2, 3, 4, 5 };
|
||||
int[] arr = { 1, 2, 3, 4, 5 };
|
||||
System.out.println(
|
||||
"Minimum number of multiplications is " + Memoized_Matrix_Chain(arr)
|
||||
);
|
||||
|
Reference in New Issue
Block a user