题解 | 矩阵乘法计算量估算
while True:
try:
n = int(input())
arr = [] # 装填输入的矩阵
order = [] # 处理出入栈的矩阵
res = 0 # 乘法次数
for i in range(n):
arr.append(list(map(int,input().split())))
f = input()
count = 0
for i in f:
if i.isalpha():
order.append(arr[count]) # 将字符串的字母依序转化成arr对应的矩阵
count += 1
elif i == ')' and len(order) >=2: # 碰到‘)’并且此时栈内有两个以上矩阵,开始计算
b = order.pop()
a = order.pop()
res += a[1]*b[1]*a[0] # 累计每次乘法次数
order.append([a[0],b[1]]) # 将计算后得到的矩阵装进栈内
print(res)
except:
break

