题解 | #矩阵乘法计算量估算#

矩阵乘法计算量估算

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)

全部评论

相关推荐

被小米连拒3次了
投递小米集团等公司10个岗位
点赞 评论 收藏
分享
头像
08-05 15:59
已编辑
门头沟学院 运维工程师
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务