Error
|
|
---|---|
@Ibrahim Nash | 6420 |
@blackshadows | 6376 |
@mb1973 | 5594 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@kirtidee18 | 3673 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3412 |
Complete Leaderboard | |
|
|
@codersgroup18 | 783 |
@Manikanta punnam | 605 |
@sriramgoparaju99 | 582 |
@rdakka | 534 |
@praveenbgp6 | 529 |
@prankursharma31 | 518 |
@yashkaril4 | 517 |
@purohitmn02 | 467 |
@sonamnigam1999 | 443 |
@sonamkumari63928 | 441 |
@shubhamstudent5 | 433 |
Complete Leaderboard |
Given a sequence of matrices, find the most efficient way to multiply these matrices together. The efficient way is the one that involves the least number of multiplications. The dimensions of the matrices are given in an array arr[] of size N (such that N = number of matrices + 1) where the ith matrix has the dimensions (arr[i-1] x arr[i]).
Example 1:
Input: N = 5
arr = {40, 20, 30, 10, 30}
Output: 26000
Explaination: There are 4 matrices of dimension
40x20, 20x30, 30x10, 10x30. Say the matrices are
named as A, B, C, D. The efficient way is
(A*(B*C))*D. The number of operations are 20*30*10
+ 40*20*10 + 40*10*30 = 26000.
Example 2:
Input: N = 4
arr = {10, 30, 5, 60}
Output: 4500
Explaination: The matrices have dimensions
10*30, 30*5, 5*60. Say the matrices are A, B
and C. The most efficient way is (A*B)*C. The
number of multiplications are 10*30*5 + 10*5*60
= 4500.
Your Task:
You do not need to take input or print anything. Your task is to complete the function matrixMultiplication() which takes the value N and the array arr[] as input parameters and returns the minimum number of multiplication operations needed to be performed.
Expected Time Complexity: O(N3)
Expected Auxiliary Space: O(N2)
Constraints:
2 ≤ N ≤ 100
1 ≤ arr[i] ≤ 500
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes