{"id":585,"date":"2026-07-06T18:32:30","date_gmt":"2026-07-06T10:32:30","guid":{"rendered":"https:\/\/mitongxue.cn\/?p=585"},"modified":"2026-07-06T18:32:30","modified_gmt":"2026-07-06T10:32:30","slug":"%e7%9f%a9%e9%98%b5%e4%b9%98%e6%b3%95%e8%ae%a1%e7%ae%97%e9%87%8f%e4%bc%b0%e7%ae%97","status":"publish","type":"post","link":"https:\/\/mitongxue.cn\/index.php\/2026\/07\/06\/%e7%9f%a9%e9%98%b5%e4%b9%98%e6%b3%95%e8%ae%a1%e7%ae%97%e9%87%8f%e4%bc%b0%e7%ae%97\/","title":{"rendered":"\u77e9\u9635\u4e58\u6cd5\u8ba1\u7b97\u91cf\u4f30\u7b97"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"673\" height=\"356\" src=\"https:\/\/mitongxue.cn\/wp-content\/uploads\/2026\/07\/image-3.png\" alt=\"\" class=\"wp-image-586\" srcset=\"https:\/\/mitongxue.cn\/wp-content\/uploads\/2026\/07\/image-3.png 673w, https:\/\/mitongxue.cn\/wp-content\/uploads\/2026\/07\/image-3-300x159.png 300w\" sizes=\"auto, (max-width: 673px) 100vw, 673px\" \/><\/figure>\n\n\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8ba1\u7b97&nbsp;<math><semantics><mrow><mi>A<\/mi><mo>\u00d7<\/mo><mi>B<\/mi><mo>\u00d7<\/mo><mi>C<\/mi><\/mrow><\/semantics><\/math><em>A<\/em>\u00d7<em>B<\/em>\u00d7<em>C<\/em>&nbsp;\u65f6\uff0c\u4e0d\u540c\u7684\u8fd0\u7b97\u987a\u5e8f\u4f1a\u5e26\u6765\u4e0d\u540c\u7684\u8fd0\u7b97\u91cf\u3002\u4f8b\u5982\uff0c<math><semantics><mrow><mo stretchy=\"false\">(<\/mo><mi>A<\/mi><mo>\u00d7<\/mo><mi>B<\/mi><mo stretchy=\"false\">)<\/mo><mo>\u00d7<\/mo><mi>C<\/mi><\/mrow><\/semantics><\/math>(<em>A<\/em>\u00d7<em>B<\/em>)\u00d7<em>C<\/em>&nbsp;\u7684\u8fd0\u7b97\u91cf\u662f&nbsp;<math><semantics><mrow><mi>a<\/mi><mo>\u00d7<\/mo><mi>b<\/mi><mo>\u00d7<\/mo><mi>c<\/mi><mo>+<\/mo><mi>a<\/mi><mo>\u00d7<\/mo><mi>c<\/mi><mo>\u00d7<\/mo><mi>d<\/mi><\/mrow><\/semantics><\/math><em>a<\/em>\u00d7<em>b<\/em>\u00d7<em>c<\/em>+<em>a<\/em>\u00d7<em>c<\/em>\u00d7<em>d<\/em>\uff0c\u800c&nbsp;<math><semantics><mrow><mi>A<\/mi><mo>\u00d7<\/mo><mo stretchy=\"false\">(<\/mo><mi>B<\/mi><mo>\u00d7<\/mo><mi>C<\/mi><mo stretchy=\"false\">)<\/mo><\/mrow><\/semantics><\/math><em>A<\/em>\u00d7(<em>B<\/em>\u00d7<em>C<\/em>)&nbsp;\u7684\u8fd0\u7b97\u91cf\u662f&nbsp;<math><semantics><mrow><mi>b<\/mi><mo>\u00d7<\/mo><mi>c<\/mi><mo>\u00d7<\/mo><mi>d<\/mi><mo>+<\/mo><mi>a<\/mi><mo>\u00d7<\/mo><mi>b<\/mi><mo>\u00d7<\/mo><mi>d<\/mi><\/mrow><\/semantics><\/math><em>b<\/em>\u00d7<em>c<\/em>\u00d7<em>d<\/em>+<em>a<\/em>\u00d7<em>b<\/em>\u00d7<em>d<\/em>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><math><semantics><mrow><mspace width=\"1.5em\"><\/mspace><\/mrow><\/semantics><\/math>\u73b0\u5728\uff0c\u5bf9\u4e8e\u7ed9\u5b9a\u7684&nbsp;<math><semantics><mrow><mi>n<\/mi><\/mrow><\/semantics><\/math><em>n<\/em>&nbsp;\u4e2a\u77e9\u9635\u7684\u5927\u5c0f\u4e0e\u8fd0\u7b97\u5f0f\uff0c\u8bf7\u4f60\u8ba1\u7b97\u51fa\u6240\u9700\u8981\u7684\u8fd0\u7b97\u91cf\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u5165\u63cf\u8ff0\uff1a<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><math><semantics><mrow><mspace width=\"1.5em\"><\/mspace><\/mrow><\/semantics><\/math>\u7b2c\u4e00\u884c\u8f93\u5165\u4e00\u4e2a\u6574\u6570&nbsp;<math><semantics><mrow><mi>n<\/mi><mrow><mo fence=\"true\">(<\/mo><mn>1<\/mn><mo>\u2266<\/mo><mi>n<\/mi><mo>\u2266<\/mo><mn>15<\/mn><mo fence=\"true\">)<\/mo><\/mrow><\/mrow><\/semantics><\/math><em>n<\/em>(1\u2266<em>n<\/em>\u226615)&nbsp;\u4ee3\u8868\u77e9\u9635\u7684\u4e2a\u6570\u3002<br><math><semantics><mrow><mspace width=\"1.5em\"><\/mspace><\/mrow><\/semantics><\/math>\u6b64\u540e&nbsp;<math><semantics><mrow><mi>n<\/mi><\/mrow><\/semantics><\/math><em>n<\/em>&nbsp;\u884c\uff0c\u7b2c&nbsp;<math><semantics><mrow><mi>i<\/mi><\/mrow><\/semantics><\/math><em>i<\/em>&nbsp;\u884c\u8f93\u5165\u4e24\u4e2a\u6574\u6570&nbsp;<math><semantics><mrow><msub><mi>a<\/mi><mi>i<\/mi><\/msub><\/mrow><\/semantics><\/math><em>a<\/em><em>i<\/em>\u200b&nbsp;\u548c&nbsp;<math><semantics><mrow><msub><mi>b<\/mi><mi>i<\/mi><\/msub><mrow><mo fence=\"true\">(<\/mo><mn>1<\/mn><mo>\u2266<\/mo><msub><mi>a<\/mi><mi>i<\/mi><\/msub><mo separator=\"true\">,<\/mo><msub><mi>b<\/mi><mi>i<\/mi><\/msub><mo>\u2266<\/mo><mn>100<\/mn><mo fence=\"true\">)<\/mo><\/mrow><\/mrow><\/semantics><\/math><em>b<\/em><em>i<\/em>\u200b(1\u2266<em>a<\/em><em>i<\/em>\u200b,<em>b<\/em><em>i<\/em>\u200b\u2266100)&nbsp;\u4ee3\u8868\u7b2c&nbsp;<math><semantics><mrow><mi>i<\/mi><\/mrow><\/semantics><\/math><em>i<\/em>&nbsp;\u4e2a\u77e9\u9635\u7684\u884c\u6570\u548c\u5217\u6570\u3002<br><math><semantics><mrow><mspace width=\"1.5em\"><\/mspace><\/mrow><\/semantics><\/math>\u6700\u540e\u4e00\u884c\u8f93\u5165\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;<math><semantics><mrow><mn>1<\/mn><mo>\u2266<\/mo><mrow><mi mathvariant=\"normal\">l<\/mi><mi mathvariant=\"normal\">e<\/mi><mi mathvariant=\"normal\">n<\/mi><\/mrow><mo stretchy=\"false\">(<\/mo><mi>s<\/mi><mo stretchy=\"false\">)<\/mo><mo>\u2266<\/mo><mn>1<\/mn><msup><mn>0<\/mn><mn>3<\/mn><\/msup><\/mrow><\/semantics><\/math>1\u2266len(<em>s<\/em>)\u2266103&nbsp;\u7684\u5b57\u7b26\u4e32&nbsp;<math><semantics><mrow><mi>s<\/mi><\/mrow><\/semantics><\/math><em>s<\/em>&nbsp;\u4ee3\u8868\u8fd0\u7b97\u5f0f\u3002\u8fd0\u7b97\u5f0f\u4e2d\u53ea\u5305\u542b\u524d&nbsp;<math><semantics><mrow><mi>n<\/mi><\/mrow><\/semantics><\/math><em>n<\/em>&nbsp;\u4e2a\u5927\u5199\u5b57\u6bcd\u4e0e\u62ec\u53f7\uff0c\u7b2c&nbsp;<math><semantics><mrow><mi>i<\/mi><\/mrow><\/semantics><\/math><em>i<\/em>&nbsp;\u4e2a\u5927\u5199\u5b57\u6bcd\u5bf9\u5e94\u8f93\u5165\u7684\u7b2c&nbsp;<math><semantics><mrow><mi>i<\/mi><\/mrow><\/semantics><\/math><em>i<\/em>&nbsp;\u4e2a\u77e9\u9635\uff0c\u62ec\u53f7\u6210\u5bf9\u51fa\u73b0\uff0c\u4fdd\u8bc1\u8fd0\u7b97\u5f0f\u5408\u6cd5\u4e14\u6b63\u786e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u51fa\u63cf\u8ff0\uff1a<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><math><semantics><mrow><mspace width=\"1.5em\"><\/mspace><\/mrow><\/semantics><\/math>\u5728\u4e00\u884c\u4e0a\u8f93\u51fa\u4e00\u4e2a\u6574\u6570\uff0c\u4ee3\u8868\u8ba1\u7b97\u9700\u8981\u7684\u8fd0\u7b97\u91cf\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b1<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>3\n50 10\n10 20\n20 5\n(A(BC))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>3500<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>3\n50 10\n10 20\n20 5\n((AB)C)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>15000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3b\u8981\u9700\u8981\u5904\u7406\u5165\u6808\u51fa\u6808\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u601d\u8def\uff1a\u6808\u6a21\u62df\u8fd0\u7b97<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6808\u5b58\u77e9\u9635\u4fe1\u606f <code>{row, col, cost}<\/code>\uff08\u884c\u5217 + \u7d2f\u8ba1\u6d88\u8017\uff09<\/li>\n\n\n\n<li>\u9047\u5230\u5b57\u6bcd\uff1a\u628a\u5bf9\u5e94\u77e9\u9635\u538b\u6808<\/li>\n\n\n\n<li>\u9047\u5230 <code>)<\/code>\uff1a\u4e0d\u65ad\u5f39\u51fa\u6808\u9876\u4e24\u4e2a\u77e9\u9635\u76f8\u4e58\uff0c\u5408\u5e76\u6210\u65b0\u77e9\u9635\uff0c\u7d2f\u52a0\u8ba1\u7b97\u91cf\uff0c\u7ed3\u679c\u91cd\u65b0\u5165\u6808<\/li>\n\n\n\n<li><code>(<\/code> \u76f4\u63a5\u5ffd\u7565<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>const rl = require(\"readline\").createInterface({ input: process.stdin });\nvar iter = rl&#91;Symbol.asyncIterator]();\nconst readline = async () => (await iter.next()).value;\n\nvoid (async function () {\n    \/\/ Write your code here\n    let ptr = 0;\n    const n = await readline();\n    \/\/console.log(n);\n    const mat = &#91;];\n    for (let i = 0; i &lt; n; i++) {\n        const &#91;r, c] = (await readline()).split(\" \").map(Number);\n        mat.push({ r, c });\n    }\n    const expr = await readline();\n    \/\/console.log(mat)\n    \/\/console.log(expr)\n\n    const stack = &#91;];\n    let total = 0;\n\n    for (const ch of expr) {\n        \/\/console.log(ch)\n        if(ch==='(') continue;\n        if(ch===')'){\n            const right = stack.pop();\n            const left = stack.pop();\n            \/\/\u8ba1\u7b97\u5f00\u9500\n            const cost = left.r * left.c * right.c;\n            total+= cost;\n            stack.push({r:left.r, c:right.c});\n        }else{\n            const idx = ch.charCodeAt() - \"A\".charCodeAt();\n            \/\/console.log(ch,\"----\",idx);\n            stack.push(mat&#91;idx]);\n        }\n    }\n    console.log(total)\n})();\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8ba1\u7b97&nbsp;A\u00d7B\u00d7CA\u00d7B\u00d7C&nbsp;..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,11],"tags":[49],"class_list":["post-585","post","type-post","status-publish","format-standard","hentry","category-js","category-front","tag-49"],"featured_image_urls":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":""},"author_info":{"info":["\u9648 \u67d0\u4eba"]},"category_info":"<a href=\"https:\/\/mitongxue.cn\/index.php\/category\/front\/js\/\" rel=\"category tag\">JS<\/a> <a href=\"https:\/\/mitongxue.cn\/index.php\/category\/front\/\" rel=\"category tag\">\u524d\u7aef<\/a>","tag_info":"\u524d\u7aef","comment_count":"0","_links":{"self":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/comments?post=585"}],"version-history":[{"count":1,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/585\/revisions"}],"predecessor-version":[{"id":587,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/585\/revisions\/587"}],"wp:attachment":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/media?parent=585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/categories?post=585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/tags?post=585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}