题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
def jc(x,y): return ((x[0],y[1]),x[0]*x[1]*y[1]) n=int(input()) ls=[] for i in range(n): ls.append(tuple(map(lambda x:int(x),input().split(" ")))) rule=input() ls2=[x if x in ("(",")") else ls[ord(x)-ord("A")] for x in rule] count=0 while True: if len(ls2)<=1: break start=0 for i in range(len(ls2)): if ls2[i]=="(": start=i elif ls2[i]==")": if((i-start)==2): x=ls2[start+1] else: x=ls2[start+1] for j in range(start+2,i): result=jc(x,ls2[j]) x=result[0] count+=result[1] ls2 = ls2[:start]+ls2[i+1:] ls2.insert(start,x) break print(count)