题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
while True: try: 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: if i.isalpha(): order.append(arr[ord(i)-65]) elif i ==")": b = order.pop() a = order.pop() res +=a[1]*b[1]*a[0] order.append([a[0],b[1]]) print(res) except: break
题目的输入已经规避掉任何在括号内出现三个及三个以上矩阵的情况,所以 在13行不需要判断len(order)>=2