Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,875
Solved Threads: 953
Skill Endorsements: 27
>programme that find the optimal parenthesization of a matrix-chain product
Try reading this:-
http://en.wikipedia.org/wiki/Matrix_chain_multiplication
>then perform the optimal matrix -chain multiply 4 a sequence of matrices
Multiplication would go something like this:-
public static void mmult (int rows, int cols,
int[][] m1, int[][] m2, int[][] m3) {
for (int i=0; i<rows; i++) {
for (int j=0; j<cols; j++) {
int val = 0;
for (int k=0; k<cols; k++) {
val += m1[i][k] * m2[k][j];
}
m3[i][j] = val;
}
}
}
>but the user should enter the number of the matrices and its dimensions.........
I assume you know what cin is and how to initialise a 2D array?
iamthwee
Posting Genius
6,373 posts since Aug 2005
Reputation Points: 1,567
Solved Threads: 489
Skill Endorsements: 35