题解 | #矩阵乘法计算量估算#
矩阵乘法计算量估算
https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { const n = parseInt(await readline()); const nums = []; for(let i = 0; i < n; i++){ nums.push((await readline()).split(" ").map(Number)); } const str = await readline(); const stack = []; let cnt = 0; let index = 0; for(const c of str){ // console.log(stack,cnt) if(c === "("){ continue; }else if(c === ")"){ let second = stack.pop(); let first = stack.pop(); cnt += first[0] * first[1] * second[1]; stack.push([first[0],second[1]]); }else{ // stack.push(nums[c.charCodeAt()-"A".charCodeAt()]); stack.push(nums[index++]);//为了摆脱对字母的依赖 } } console.log(cnt); }()