题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
http://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
Python 代码实现:
while True:
try:
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
num = 0
n = int(input())
dict_a = {}
for i in range(n):
dict_a[alpha[i]] = list(map(int,input().split()))
rules = input()
stack = []
for j in rules:
if j != ')':
stack.append(j)
else:
C,B = stack.pop(),stack.pop()
stack.pop()
num += dict_a[B][0] * dict_a[B][1] * dict_a[C][1]
dict_a[B] = [dict_a[B][0],dict_a[C][1]]
stack.append(B)
print(num)
except:
break