a1 = [
[1,2]
]
a4 = [
[2,3,4],
[3,4,5]
]
a2 = [
[4,5,6,7],
[5,6,7,8],
[6,7,8,9]
]
a3 = [
[10,11,12,13,14,15],
[11,12,13,14,15,16],
[12,13,14,15,16,17],
[13,14,15,16,17,18]
]
#123=6 134=12 146=24
def sortai():
aa = [len(a1),len(a2),len(a3),len(a4)]
return aa
def maxai():
returnmax(len(a1[0]),len(a2[0]),len(a3[0]),len(a4[0]))
defmintimes(a,b,c,d,e):
f1 = a*b*c+a*c*d+a*d*e
f2 = a*b*c+c*d*e+a*c*e
f3 = b*c*d+b*d*e+a*b*e
f4 = b*c*d+a*b*d+a*d*e
return min(f1,f2,f3,f4)
if __name__=='__main__':
ss=sortai()
print(mintimes(ss[0],ss[1],ss[2],ss[3],maxai()))
动态规划算法 求4个矩阵连乘的最少量。
最新推荐文章于 2024-10-13 22:30:10 发布