题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
import string def compute1(a,b): re1 = a[0]*b[1]*a[1] re2 = [a[0],b[1]] return re1,re2 num = int(input().strip()) table1 = {} list1 = [x for x in string.ascii_uppercase] for i in range(num): table1[list1[i]] = list(map(int,input().strip().split(" "))) str1 = list(input().strip()[::-1]) resault1 = 0 def compute2(str1): putemp = [] global resault1 while str1: temp1 = str1.pop() if temp1 not in ['(',')']: putemp.append(table1[temp1]) elif temp1 == '(': temp1 = compute2(str1) putemp.append(temp1) elif temp1 == ')': return putemp[0] if len(putemp) == 2: re1,re2 = compute1(putemp[0],putemp[1]) resault1 +=re1 putemp = [] putemp.append(re2) finall = compute2(str1) print(resault1)