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

矩阵乘法计算量估算

https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b

num = int(input())
l = []
w = []
for i in range(num):
    ll , ww = map(int, input().split())
    l.append(ll)
    w.append(ww)

s = list(input())
res = 0
while len(s) > 1:
    count = 0
    for i in range(len(s)) :
        if s[i].isalpha():
            count += 1
        elif s[i] == ')':
            del s[i-3:i+1]
            s.insert(i - 3, 'A')
            l1 = l.pop(count -2)
            l2 = l.pop(count -2)
            w1 = w.pop(count -2)
            w2 = w.pop(count -2)
            res += l1 * w1 * w2
            l.insert(count - 2,l1)
            w.insert(count - 2, w2)
            break
print(res)

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务