题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int count(vector<pair<int,int>> &vec, int a, int b){
int sum;
sum = vec[a].first * vec[a].second * vec[b].second;
vec[a] = make_pair(vec[a].first,vec[b].second);
//vec.erase(vec.begin() + b);
return sum;
}
int main() {
int n;
cin>>n;
vector<pair<int,int>> vec;
while (n--){
int a,b;
cin>>a>>b;
vec.push_back(make_pair(a,b));
}
stack<char> st;
string str;
cin >> str;
int result = 0;
for (auto ch : str){
if (ch == '(')
continue;
if (ch == ')'){
if (st.size() > 1){
int num_2 = st.top() - 'A';
st.pop();
//int num_1 = st.top() - 'A';
//st.pop();
result += count(vec, st.top() - 'A', num_2);
//cout<<"1:"<<result<<endl;
}
}
else st.push(ch);
}
cout << result;
}
// 64 位输出请用 printf("%lld")


腾讯云智研发成长空间 5088人发布