From 72168d8050eb82b42b99fb0c8f3102dccfe8e758 Mon Sep 17 00:00:00 2001 From: baljeetkumar <31220499+baljeetkumar@users.noreply.github.com> Date: Sat, 27 Oct 2018 22:51:29 +0530 Subject: [PATCH] matrix_chain_mul --- matrix_chain_mul.txt | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 matrix_chain_mul.txt diff --git a/matrix_chain_mul.txt b/matrix_chain_mul.txt new file mode 100644 index 0000000..650a39b --- /dev/null +++ b/matrix_chain_mul.txt @@ -0,0 +1,53 @@ +#include +#include + +// Matrix Ai has dimension p[i-1] x p[i] for i = 1..n +int MatrixChainOrder(int p[], int n) +{ + + /* For simplicity of the program, one extra row and one + extra column are allocated in m[][]. 0th row and 0th + column of m[][] are not used */ + int m[n][n]; + + int i, j, k, L, q; + + /* m[i,j] = Minimum number of scalar multiplications needed + to compute the matrix A[i]A[i+1]...A[j] = A[i..j] where + dimension of A[i] is p[i-1] x p[i] */ + + // cost is zero when multiplying one matrix. + for (i=1; i