我是否会根据计算的两个矩阵对带有括号的矩阵进行排序,例如(A1)(A2(A3A4))
import sys
s=[[]]
from pprint import pprint
def order(i,j):
if(i==j):
print("A" + str(i))
else:
k = s[i][j]
print("(")
order(i,k)
order(k+1,j)
print(")")
def minmult(p, n,par):
m = [[0 for x in range(n)] for x in range(n)]
s = [[0 for x in range(n)] for x in range(n)]
for i in range(1, n):
m[i][i] = 0
s[i][i] = 0
for L in range(2, n):
for i in range(1, n-L+1):
j = i+L-1
m[i][j] = sys.maxsize
for k in range(i, j):
q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]
if q < m[i][j]:
m[i][j] = q
s[i][j]=k
print(str(order(i,j)))
pprint(m)
pprint(s)
return m[1][n-1]
array=[10,4,5,20,2,50]
size = len(array)
print(str(minmult(array,size,0)))
不知道如何使方法顺序有效,任何帮助都会很棒。