题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
while 1: try: n = int(input()) matrix_row_col = [[0]*2 for _ in range(n)] matrix_name = [] for i in range(n): matrix_name.append(chr(ord('A') + i)) for i in range(n): matrix_row_col[i] = list(map(int, input().split())) evalution = list(input()) Stack = [] num = 0 for c in evalution: if c == '(': continue elif c.isalpha(): Stack.append(matrix_row_col[matrix_name.index(c)]) elif c == ')': b_data = Stack.pop() a_data = Stack.pop() num = num + a_data[0] * a_data[1] * b_data[1] Stack.append([a_data[0], b_data[1]]) print(num) except: break