# How to use 'matrix chain multiplication calculator' in Python

Every line of 'matrix chain multiplication calculator' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure. ## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``12def matrixChainMultiply(seq):13    '''matrix chain multiply, find the optimalest comb to multiply14        eg ABCD,  (AB)(CD), A((BC)D)15        seq: sequence of matrix's scale, eg [A.row,A.col,B.col,C.col,D.col]16    '''17    print(seq)18    n = len(seq)-119    mat = [*n for i in range(n)]20    mark = [*n for i in range(n)]21    for l in range(1,n):22        for i in range(n):23            j = i+l24            if j>=n: continue25            mat[i][j] = None26            for k in range(i,j):27                tmp = mat[i][k]+mat[k+1][j]+seq[i]*seq[k+1]*seq[j+1]28                if mat[i][j] is None or mat[i][j]>tmp:29                    mark[i][j] = k30                    mat[i][j]= tmp31    s= findSolution(mark,0,n-1)32    print(s)33    return mat[n-1]``