题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
# 2024年10月31日 周四 上午11:36 """ 3 50 10 10 20 20 5 (A(BC)) """ n = int(input()) # 要计算乘法的矩阵个数n ls = [] for i in range(n): ls.append(list(map(int, input().split()))) #print(ls) f = input() #print(f) stack = [] p = 0 for i in f: if i.isalpha(): stack.append(ls[ord(i) - 65]) elif i == ")" and len(stack) >= 2: c = stack.pop() # C b = stack.pop() # B p += b[0] * b[1] * c[1] # p = m*n*p,注意顺序 stack.append([b[0], c[1]]) print(p)