题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
''' 3 50 10 10 20 20 5 (A(BC)) ''' # 3500 n = int(input()) # 矩阵个数n ls = [] guize = [] cc = 0 for i in range(n): ls.append(list(map(int,input().split()))) s = input() # 计算规则: (A(BC)) for i in s: if i.isalpha(): guize.append(ls[ord(i)-65])# 将字母转换成第几个矩阵的处理信息 elif i == ')' and len(guize) >= 2: c = guize.pop() #先弹出的是后输入的 b = guize.pop() cc += b[0]*c[1]*b[1] guize.append([b[0],c[1]]) print(cc)