题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
http://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
n=int(input())
num=[]
for i in range(n):
num.append(input().split())
s=input()
#print(num)
def f(a,lst,n):
n+=int(lst[a][0])*int(lst[a][1])*int(lst[a+1][1])
#print(str(lst[a][0])+str(lst[a][1])+str(lst[a+1][1]))
d=lst[a+1][1]
lst[a][1]=d
#print(d)
lst.remove(lst[a+1])
#print('替换完成:'+str(lst)+'得到n'+str(n))
return lst,n
m=0
for _ in range(14):
c=0
for k in s:
if k.isalpha():
c+=1
if c==1:
print(m)
break
for i in range(len(s)):
#print('i='+str(i))
if s[i]=='(' and s[i+1].isalpha() and s[i+2].isalpha() and s[i+3]==')':
cou=0
for j in s[:i]:
if j.isalpha():
cou+=1
#print(str(cou))
num,m=f(cou,num,m)
s=s.replace('('+str(s[i+1])+str(s[i+2])+')','Z')
#print('替换字母后为'+s)
break