题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
while True: try: n = int(input()) # 参与运算的矩阵个数 diclist = [] # 用来存储矩阵信息 poplist = [] # 存储出栈元素 num = 0 # 记录此时进栈元素的数量 countsum = 0 # 初始化乘法计算次数 for i in range(n): diclist.append(list(map(int,input().split()))) countlist = list(input()) for i,e in enumerate(countlist): if 'A' <= e <= 'Z': poplist.append(diclist[num]) num += 1 elif e == ')': # 计算每次的乘法次数 countsum += poplist[-2][0] * poplist[-2][1] * poplist[-1][1] # 元素进行出栈 a = poplist.pop() b = poplist.pop() # 计算得到新矩阵后重新进栈 poplist.append([b[0],a[1]]) print(countsum) except: break