题解 | 矩阵乘法计算量估算
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
#include <iostream>
#include <stack>
using namespace std;
int calulate(int a,int b,int c){
return a*b*c;
}
int main() {
int N;
cin>>N;
int a[N][2];
for(int i = 0;i<N;i++){
cin>>a[i][0]>>a[i][1];
}
string s;
cin>>s;
stack<int> st1;
stack<char> st2;
int ans = 0;
pair<int,int> p;
for(auto i : s){
if(i!=')'&&i!='('){
st2.push(i);
p = {a[i-'A'][0],a[i-'A'][1]};
}else if(i=='('){
st1.push(i);
}else{
st2.pop();
char temp = st2.top();
ans += calulate(a[temp-'A'][0],p.first,p.second);
p = {a[temp-'A'][0],p.second};
}
}
cout<<ans;
// for(int i = 0;i<N;i++){
// for(int j = 0;j<2;j++){
// cout<<a[i][j]<<" ";
// }
// }
return 0;
}

