mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-24 04:54:21 +08:00
@ -28,10 +28,8 @@ 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,12 +38,10 @@ public class MatrixChainRecursiveTopDownMemoisation {
|
||||
return m[i][j];
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user