题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
n = int(input()) # 矩阵的个数
arr = [] # 存储矩阵
order = [] # 存储计算法则
res = 0
#输入矩阵的行列信息
for i in range(n):
arr.append(list(map(int,input().split())))
# 输入计算法则
f = input()
# 遍历运算法则
for i in f: # f=(A(BC))
if i.isalpha():
order.append(arr[ord(i)-65])
elif i == ')' and (len(order) >= 2):
a = order.pop() # 取出矩阵C=[20,5]
b = order.pop() # 取出矩阵B=[10,20]
res += b[0]*a[1]*a[0] # 累计
order.append([b[0],a[1]]) # [10,5]
print(res)
曼迪匹艾公司福利 115人发布
