Format code with prettier (#3375)

This commit is contained in:
acbin
2022-10-03 17:23:00 +08:00
committed by GitHub
parent 32b9b11ed5
commit e96f567bfc
464 changed files with 11483 additions and 6189 deletions

View File

@ -2,7 +2,7 @@ package com.thealgorithms.dynamicprogramming;
// Matrix-chain Multiplication
// Problem Statement
// we have given a chain A1,A2,...,Ani of n matrices, where for i = 1,2,...,n,
// we have given a chain A1,A2,...,Ani of n matrices, where for i = 1,2,...,n,
// matrix Ai has dimension pi1 ×pi
// , fully parenthesize the product A1A2 ···An in a way that
// minimizes the number of scalar multiplications.
@ -28,7 +28,10 @@ public class MatrixChainRecursiveTopDownMemoisation {
return m[i][j];
} else {
for (int k = i; k < j; k++) {
int q = Lookup_Chain(m, p, i, k) + Lookup_Chain(m, p, k + 1, j) + (p[i - 1] * p[k] * p[j]);
int q =
Lookup_Chain(m, p, i, k) +
Lookup_Chain(m, p, k + 1, j) +
(p[i - 1] * p[k] * p[j]);
if (q < m[i][j]) {
m[i][j] = q;
}
@ -40,8 +43,9 @@ 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};
System.out.println("Minimum number of multiplications is " + Memoized_Matrix_Chain(arr));
int arr[] = { 1, 2, 3, 4, 5 };
System.out.println(
"Minimum number of multiplications is " + Memoized_Matrix_Chain(arr)
);
}
}