题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
#include <cctype> #include <iostream> #include <stack> #include <vector> using namespace std; int main() { int n; while (cin >> n) { vector<pair<int, int>> sz(n); for(int i=0;i<n;i++){ cin>>sz[i].first>>sz[i].second; } string s; cin>>s; int ret = 0; stack<pair<int, int>> stk; for(int i=0;i<s.size();i++){ if(s[i]==')'){ auto y = stk.top(); stk.pop(); auto x = stk.top(); stk.pop(); ret+=x.first*x.second*y.second; stk.push({x.first, y.second}); } else if(s[i]!='('){ int k = s[i]-'A'; stk.push(sz[k]); } } cout<<ret; } }