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

矩阵乘法计算量估算

https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b?tpId=37&tqId=21293&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=3&judgeStatus=undefined&tags=&title=

n = int(input())
a = [0] * n
b = [0] * n

for i in range(n):
    a[i], b[i] = map(int, input().split(" "))

s = input()

ans = 0
stack = []
for ch in s:
    if ch == ')':
        b1, b2 = stack.pop()
        a1, a2 = stack.pop()
        ans += a1 * a2 * b2
        stack.append([a1, b2])
    elif ch != '(':
        idx = ord(ch) - ord('A')
        stack.append([a[idx], b[idx]])
print(ans)

全部评论

相关推荐

把球:这个听过,你加了就会发现是字节的hr
点赞 评论 收藏
分享
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务