{"id":4020,"date":"2019-12-16T11:06:38","date_gmt":"2019-12-16T03:06:38","guid":{"rendered":"https:\/\/damogame.cn\/wordpress\/?p=4020"},"modified":"2019-12-16T11:06:38","modified_gmt":"2019-12-16T03:06:38","slug":"%e5%93%88%e5%a4%ab%e6%9b%bc%e6%a0%91","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/4020","title":{"rendered":"\u54c8\u592b\u66fc\u6811"},"content":{"rendered":"<p><a href=\"https:\/\/www.cnblogs.com\/Atanisi\/p\/8672540.html\">\u539f\u6587\u5730\u5740<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2><strong>1. \u54c8\u592b\u66fc\u6811\u4e5f\u79f0\u6700\u4f18\u4e8c\u53c9\u6811\u3002<\/strong><\/h2>\n<p><strong>\u53f6\u5b50\u8282\u70b9\u7684\u6743\u503c<\/strong>\u662f\u5bf9\u53f6\u5b50\u8282\u70b9\u8d4b\u4e88\u7684\u4e00\u4e2a\u6709\u610f\u4e49\u7684\u6570\u503c\u91cf\u3002<\/p>\n<p>\u8bbe\u4e8c\u53c9\u6811\u5177\u6709 n \u4e2a\u5e26\u6743\u503c\u7684\u53f6\u5b50\u7ed3\u70b9\uff0c\u4ece\u6839\u8282\u70b9\u5230\u5404\u4e2a\u53f6\u5b50\u7ed3\u70b9\u7684\u8def\u5f84\u957f\u5ea6\u4e0e\u76f8\u5e94\u53f6\u5b50\u7ed3\u70b9\u6743\u503c\u7684\u4e58\u79ef\u4e4b\u548c\u53eb\u505a<strong>\u4e8c\u53c9\u6811\u7684\u5e26\u6743\u8def\u5f84\u957f\u5ea6\u3002<\/strong><\/p>\n<p><strong>\u3000<\/strong>\u7ed9\u5b9a\u4e00\u7ec4\u5177\u6709\u786e\u5b9a\u6743\u503c\u7684\u53f6\u5b50\u7ed3\u70b9\uff0c\u53ef\u4ee5\u6784\u9020\u5904\u4e0d\u540c\u7684\u4e8c\u53c9\u6811\uff0c\u5c06\u5176\u4e2d\u5e26\u6743\u8def\u5f84\u957f\u5ea6\u6700\u5c0f\u7684\u4e8c\u53c9\u6811\u79f0\u4e3a<strong>\u54c8\u592b\u66fc\u6811<\/strong>\u3002<\/p>\n<h2><strong>2. \u57fa\u672c\u601d\u60f3\uff1a<\/strong><\/h2>\n<ul>\n<li><strong>\u521d\u59cb\u5316<\/strong>\uff1a\u7531\u7ed9\u5b9a\u7684 n \u4e2a\u6743\u503c\u00a0<span id=\"MathJax-Element-1-Frame\" class=\"MathJax\" style=\"margin: 0px; padding: 0px; display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 12px; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mrow&gt;&lt;mo&gt;{&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;&amp;#x03C9;&lt;\/mi&gt;&lt;mrow class=&quot;MJX-TeXAtom-ORD&quot;&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msub&gt;&lt;mo&gt;,&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;&amp;#x03C9;&lt;\/mi&gt;&lt;mrow class=&quot;MJX-TeXAtom-ORD&quot;&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msub&gt;&lt;mo&gt;,&lt;\/mo&gt;&lt;mo&gt;&amp;#x22EF;&lt;\/mo&gt;&lt;mo&gt;,&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;&amp;#x03C9;&lt;\/mi&gt;&lt;mrow class=&quot;MJX-TeXAtom-ORD&quot;&gt;&lt;mi&gt;n&lt;\/mi&gt;&lt;\/mrow&gt;&lt;\/msub&gt;&lt;mo&gt;}&lt;\/mo&gt;&lt;\/mrow&gt;&lt;\/math&gt;\"><span id=\"MathJax-Span-1\" class=\"math\"><span id=\"MathJax-Span-2\" class=\"mrow\"><span id=\"MathJax-Span-3\" class=\"mrow\"><span id=\"MathJax-Span-4\" class=\"mo\">{<\/span><span id=\"MathJax-Span-5\" class=\"msubsup\"><span id=\"MathJax-Span-6\" class=\"mi\">\u03c9<\/span><span id=\"MathJax-Span-7\" class=\"texatom\"><span id=\"MathJax-Span-8\" class=\"mrow\"><span id=\"MathJax-Span-9\" class=\"mn\">1<\/span><\/span><\/span><\/span><span id=\"MathJax-Span-10\" class=\"mo\">,<\/span><span id=\"MathJax-Span-11\" class=\"msubsup\"><span id=\"MathJax-Span-12\" class=\"mi\">\u03c9<\/span><span id=\"MathJax-Span-13\" class=\"texatom\"><span id=\"MathJax-Span-14\" class=\"mrow\"><span id=\"MathJax-Span-15\" class=\"mn\">2<\/span><\/span><\/span><\/span><span id=\"MathJax-Span-16\" class=\"mo\">,<\/span><span id=\"MathJax-Span-17\" class=\"mo\">\u22ef<\/span><span id=\"MathJax-Span-18\" class=\"mo\">,<\/span><span id=\"MathJax-Span-19\" class=\"msubsup\"><span id=\"MathJax-Span-20\" class=\"mi\">\u03c9<\/span><span id=\"MathJax-Span-21\" class=\"texatom\"><span id=\"MathJax-Span-22\" class=\"mrow\"><span id=\"MathJax-Span-23\" class=\"mi\">n<\/span><\/span><\/span><\/span><span id=\"MathJax-Span-24\" class=\"mo\">}<\/span><\/span><\/span><\/span><span class=\"MJX_Assistive_MathML\" role=\"presentation\">{\u03c91,\u03c92,\u22ef,\u03c9n}<\/span><\/span>\u6784\u9020 n \u68f5\u53ea\u6709\u4e00\u4e2a\u6839\u8282\u70b9\u7684\u4e8c\u53c9\u6811\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u4e8c\u53c9\u6811\u96c6\u5408<span id=\"MathJax-Element-2-Frame\" class=\"MathJax\" style=\"margin: 0px; padding: 0px; display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 12px; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;F&lt;\/mi&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mrow&gt;&lt;mo&gt;{&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;T&lt;\/mi&gt;&lt;mrow class=&quot;MJX-TeXAtom-ORD&quot;&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msub&gt;&lt;mo&gt;,&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;T&lt;\/mi&gt;&lt;mrow class=&quot;MJX-TeXAtom-ORD&quot;&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msub&gt;&lt;mo&gt;,&lt;\/mo&gt;&lt;mo&gt;&amp;#x22EF;&lt;\/mo&gt;&lt;mo&gt;,&lt;\/mo&gt;&lt;msub&gt;&lt;mi&gt;T&lt;\/mi&gt;&lt;mrow class=&quot;MJX-TeXAtom-ORD&quot;&gt;&lt;mi&gt;n&lt;\/mi&gt;&lt;\/mrow&gt;&lt;\/msub&gt;&lt;mo&gt;}&lt;\/mo&gt;&lt;\/mrow&gt;&lt;\/math&gt;\"><span id=\"MathJax-Span-25\" class=\"math\"><span id=\"MathJax-Span-26\" class=\"mrow\"><span id=\"MathJax-Span-27\" class=\"mi\">F<\/span><span id=\"MathJax-Span-28\" class=\"mo\">=<\/span><span id=\"MathJax-Span-29\" class=\"mrow\"><span id=\"MathJax-Span-30\" class=\"mo\">{<\/span><span id=\"MathJax-Span-31\" class=\"msubsup\"><span id=\"MathJax-Span-32\" class=\"mi\">T<\/span><span id=\"MathJax-Span-33\" class=\"texatom\"><span id=\"MathJax-Span-34\" class=\"mrow\"><span id=\"MathJax-Span-35\" class=\"mn\">1<\/span><\/span><\/span><\/span><span id=\"MathJax-Span-36\" class=\"mo\">,<\/span><span id=\"MathJax-Span-37\" class=\"msubsup\"><span id=\"MathJax-Span-38\" class=\"mi\">T<\/span><span id=\"MathJax-Span-39\" class=\"texatom\"><span id=\"MathJax-Span-40\" class=\"mrow\"><span id=\"MathJax-Span-41\" class=\"mn\">2<\/span><\/span><\/span><\/span><span id=\"MathJax-Span-42\" class=\"mo\">,<\/span><span id=\"MathJax-Span-43\" class=\"mo\">\u22ef<\/span><span id=\"MathJax-Span-44\" class=\"mo\">,<\/span><span id=\"MathJax-Span-45\" class=\"msubsup\"><span id=\"MathJax-Span-46\" class=\"mi\">T<\/span><span id=\"MathJax-Span-47\" class=\"texatom\"><span id=\"MathJax-Span-48\" class=\"mrow\"><span id=\"MathJax-Span-49\" class=\"mi\">n<\/span><\/span><\/span><\/span><span id=\"MathJax-Span-50\" class=\"mo\">}<\/span><\/span><\/span><\/span><span class=\"MJX_Assistive_MathML\" role=\"presentation\">F={T1,T2,\u22ef,Tn}<\/span><\/span>\u3002<\/li>\n<li><strong>\u9009\u53d6\u4e0e\u5408\u5e76\uff1a<\/strong>\u5728<span id=\"MathJax-Element-3-Frame\" class=\"MathJax\" style=\"margin: 0px; padding: 0px; display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 12px; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;F&lt;\/mi&gt;&lt;\/math&gt;\"><span id=\"MathJax-Span-51\" class=\"math\"><span id=\"MathJax-Span-52\" class=\"mrow\"><span id=\"MathJax-Span-53\" class=\"mi\">F<\/span><\/span><\/span><span class=\"MJX_Assistive_MathML\" role=\"presentation\">F<\/span><\/span>\u4e2d\u9009\u53d6\u6839\u8282\u70b9\u7684\u6743\u503c\u6700\u5c0f\u7684\u4e24\u9897\u4e8c\u53c9\u6811\u5206\u522b\u4f5c\u4e3a\u5de6\u53f3\u5b50\u6811\u6784\u9020\u4e00\u68f5\u65b0\u7684\u4e8c\u53c9\u6811\uff08\u4e00\u822c\u60c5\u51b5\u4e0b\u5c06<strong>\u6743\u503c\u5927\u7684\u7ed3\u70b9\u4f5c\u4e3a\u53f3\u5b50\u6811<\/strong>\u3002\uff09\uff0c\u8fd9\u68f5\u65b0\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u7684\u6743\u503c\u4e3a\u5176\u5de6\u3001\u53f3\u5b50\u6811\u6839\u8282\u70b9\u7684\u6743\u503c\u4e4b\u548c\u3002<\/li>\n<li><strong>\u5220\u9664\u4e0e\u52a0\u5165<\/strong>\uff1a\u5728<span id=\"MathJax-Element-4-Frame\" class=\"MathJax\" style=\"margin: 0px; padding: 0px; display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 12px; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;F&lt;\/mi&gt;&lt;\/math&gt;\"><span id=\"MathJax-Span-54\" class=\"math\"><span id=\"MathJax-Span-55\" class=\"mrow\"><span id=\"MathJax-Span-56\" class=\"mi\">F<\/span><\/span><\/span><span class=\"MJX_Assistive_MathML\" role=\"presentation\">F<\/span><\/span>\u4e2d\u5220\u9664\u4f5c\u4e3a\u5de6\u3001\u53f3\u5b50\u6811\u7684\u4e24\u68f5\u4e8c\u53c9\u6811\uff0c\u5e76\u5c06\u65b0\u5efa\u7acb\u7684\u4e8c\u53c9\u6811\u52a0\u5165\u5230<span id=\"MathJax-Element-5-Frame\" class=\"MathJax\" style=\"margin: 0px; padding: 0px; display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 12px; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;F&lt;\/mi&gt;&lt;\/math&gt;\"><span id=\"MathJax-Span-57\" class=\"math\"><span id=\"MathJax-Span-58\" class=\"mrow\"><span id=\"MathJax-Span-59\" class=\"mi\">F<\/span><\/span><\/span><span class=\"MJX_Assistive_MathML\" role=\"presentation\">F<\/span><\/span>\u4e2d\u3002<\/li>\n<li>\u91cd\u590d\u4e0a\u8ff0\u4e24\u4e2a\u6b65\u9aa4\uff0c\u5f53\u96c6\u5408<span id=\"MathJax-Element-6-Frame\" class=\"MathJax\" style=\"margin: 0px; padding: 0px; display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 12px; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;F&lt;\/mi&gt;&lt;\/math&gt;\"><span id=\"MathJax-Span-60\" class=\"math\"><span id=\"MathJax-Span-61\" class=\"mrow\"><span id=\"MathJax-Span-62\" class=\"mi\">F<\/span><\/span><\/span><span class=\"MJX_Assistive_MathML\" role=\"presentation\">F<\/span><\/span>\u4e2d\u53ea\u5269\u4e0b\u4e00\u68f5\u4e8c\u53c9\u6811\u65f6\uff0c\u8fd9\u68f5\u4e8c\u53c9\u6811\u4fbf\u662f\u54c8\u592b\u66fc\u6811\u3002<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/images2018.cnblogs.com\/blog\/1056313\/201803\/1056313-20180329214808213-2067448152.png\" alt=\"\" \/><\/p>\n<p>\u7531\u54c8\u592b\u66fc\u7b97\u6cd5\u6784\u9020\u7684\u54c8\u592b\u66fc\u6811\u4e2d\uff0c\u975e\u53f6\u5b50\u8282\u70b9\u7684\u5ea6\u5747\u4e3a2\u3002\u5177\u6709 n \u4e2a\u53f6\u5b50\u7ed3\u70b9\u7684\u54c8\u592b\u66fc\u6811\u516c\u6709 2n-1\u4e2a\u7ed3\u70b9\uff0c\u5176\u4e2d\u6709 n-1 \u4e2a\u975e\u53f6\u5b50\u7ed3\u70b9\u3002\u5b83\u4eec\u662f\u5728 n-1 \u6b21\u7684\u5408\u5e76\u8fc7\u7a0b\u4e2d\u751f\u4ea7\u7684\u3002<\/p>\n<h1>\u4e8c\u3001\u54c8\u592b\u66fc\u7f16\u7801<\/h1>\n<p><strong>1.\u00a0\u54c8\u592b\u66fc\u7f16\u7801\u662f\u4e00\u79cd\u53ef\u53d8\u5b57\u957f\u7f16\u7801<\/strong><\/p>\n<p>\u5982\u679c\u4e00\u7ec4\u7f16\u7801\u4e2d\u4efb\u4e00\u7f16\u7801\u90fd\u4e0d\u662f\u5176\u4ed6\u4efb\u4f55\u4e00\u4e2a\u7f16\u7801\u7684\u524d\u7f00\uff0c\u6211\u4eec\u79f0\u8fd9\u7ec4\u7f16\u7801\u4e3a\u524d\u7f00\u7f16\u7801\u3002\u54c8\u592b\u66fc\u6811\u53ef\u7528\u4e8e\u6784\u9020\u6700\u77ed\u7684\u4e0d\u7b49\u957f\u7f16\u7801\u65b9\u6848\u3002<\/p>\n<p><strong>2.\u00a0\u7b97\u6cd5\u6d41\u7a0b<\/strong><\/p>\n<p>\u89c4\u5b9a\u54c8\u592b\u66fc\u7f16\u7801\u6811\u7684\u4f5c\u5206\u652f\u4ee3\u8868 0\uff0c\u53f3\u5206\u652f\u4ee3\u8868 1\uff0c\u5219\u4ece\u6839\u7ed3\u70b9\u5230\u6bcf\u4e2a\u53f6\u5b50\u7ed3\u70b9\u6240\u7ecf\u8fc7\u7684\u8def\u5f84\u7ec4\u6210\u7684 0 \u548c 1 \u7684\u5e8f\u5217\u4fbf\u6210\u4e3a\u8be5\u53f6\u5b50\u7ed3\u70b9\u5bf9\u5e94\u5b57\u7b26\u7684\u7f16\u7801\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2018.cnblogs.com\/blog\/1056313\/201803\/1056313-20180329215739300-1069630031.png\" alt=\"\" \/><\/p>\n<p>\u89e3\u7801\u5219\u662f\u5c06\u7f16\u7801\u4e32\u4ece\u5de6\u5230\u53f3\u9010\u4f4d\u5224\u522b\uff0c\u76f4\u5230\u786e\u5b9a\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>\u54c8\u592b\u66fc\u7f16\u7801\u6811\u4e2d\uff0c\u6811\u7684\u5e26\u6743\u8def\u5f84\u957f\u5ea6\u7684\u542b\u4e49\u662f\u5404\u4e2a\u5b57\u7b26\u7684\u7801\u957f\u4e0e\u5176\u51fa\u73b0\u6b21\u6570\u7684\u4e58\u79ef\u4e4b\u548c\uff0c\u6240\u4ee5\u91c7\u7528\u54c8\u592b\u66fc\u6811\u6784\u9020\u7684\u7f16\u7801\u662f\u4e00\u79cd\u80fd\u4f7f\u5b57\u7b26\u4e32\u7684\u7f16\u7801\u603b\u957f\u5ea6\u6700\u77ed\u7684\u4e0d\u7b49\u957f\u7f16\u7801\u3002<\/p>\n<h1><strong>\u00a0\u4e09\u3001\u9898\u76ee\uff1a<\/strong><\/h1>\n<p><strong>1.\u00a0<a href=\"http:\/\/poj.org\/problem?id=3253\" target=\"_blank\" rel=\"noopener noreferrer\">POJ 3253\u00a0<\/a><\/strong><\/p>\n<p class=\"pst\">Description<\/p>\n<div class=\"ptx\" lang=\"en-US\">\n<p>Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs\u00a0<em>N<\/em>\u00a0(1 \u2264\u00a0<em>N<\/em>\u00a0\u2264 20,000) planks of wood, each having some integer length\u00a0<em>L<sub>i<\/sub><\/em>\u00a0(1 \u2264\u00a0<em>L<sub>i<\/sub><\/em>\u00a0\u2264 50,000) units. He then purchases a single long board just long enough to saw into the\u00a0<em>N<\/em>\u00a0planks (i.e., whose length is the sum of the lengths\u00a0<em>L<sub>i<\/sub><\/em>). FJ is ignoring the &#8220;kerf&#8221;, the extra length lost to sawdust when a sawcut is made; you should ignore it, too.<\/p>\n<p>FJ sadly realizes that he doesn&#8217;t own a saw with which to cut the wood, so he mosies over to Farmer Don&#8217;s Farm with this long board and politely asks if he may borrow a saw.<\/p>\n<p>Farmer Don, a closet capitalist, doesn&#8217;t lend FJ a saw but instead offers to charge Farmer John for each of the\u00a0<em>N<\/em>-1 cuts in the plank. The charge to cut a piece of wood is exactly equal to its length. Cutting a plank of length 21 costs 21 cents.<\/p>\n<p>Farmer Don then lets Farmer John decide the order and locations to cut the plank. Help Farmer John determine the minimum amount of money he can spend to create the\u00a0<em>N<\/em>\u00a0planks. FJ knows that he can cut the board in various different orders which will result in different charges since the resulting intermediate planks are of different lengths.<\/p>\n<\/div>\n<p class=\"pst\">Input<\/p>\n<div class=\"ptx\" lang=\"en-US\">Line 1: One integer\u00a0<em>N<\/em>, the number of planks<br \/>\nLines 2..<em>N<\/em>+1: Each line contains a single integer describing the length of a needed plank<\/div>\n<p class=\"pst\">Output<\/p>\n<div class=\"ptx\" lang=\"en-US\">Line 1: One integer: the minimum amount of money he must spend to make\u00a0<em>N<\/em>-1 cuts<\/div>\n<p class=\"pst\">Sample Input<\/p>\n<pre class=\"sio\">3\r\n8\r\n5\r\n8<\/pre>\n<p class=\"pst\">Sample Output<\/p>\n<pre class=\"sio\">34<\/pre>\n<p class=\"pst\">Hint<\/p>\n<div class=\"ptx\" lang=\"en-US\">He wants to cut a board of length 21 into pieces of lengths 8, 5, and 8.<br \/>\nThe original board measures 8+5+8=21. The first cut will cost 21, and should be used to cut the board into pieces measuring 13 and 8. The second cut will cost 13, and should be used to cut the 13 into 8 and 5. This would cost 21+13=34. If the 21 was cut into 16 and 5 instead, the second cut would cost 16 for a total of 37 (which is more than 34).<\/div>\n<div class=\"ptx\" lang=\"en-US\"><\/div>\n<p>\u7531\u9898\u610f\u53ef\u77e5\u5bf9\u6570\u636e\u6784\u9020Huffman\u6811\uff0c\u5176\u4e2d\u975e\u53f6\u5b50\u8282\u70b9\u7684\u503c\u52a0\u8d77\u6765\u7684\u548c\u4e3a\u6240\u6c42\u3002\u8fd9\u91cc\u65e0\u9700\u771f\u6b63\u6784\u9020\u54c8\u592b\u66fc\u6811\uff0c\u54c8\u592b\u66fc\u6811\u7684\u6784\u9020\u8fc7\u7a0b\u662f\u4e0d\u65ad\u9009\u62e9\u96c6\u5408\u79cd\u4e24\u4e2a\u6743\u503c\u6700\u5c0f\u7684\u7ed3\u70b9\uff0c\u7136\u540e\u5220\u9664\u6b64\u4e24\u7ed3\u70b9\uff0c\u52a0\u5165\u65b0\u7684\u6743\u503c\u3002\u5229\u7528\u6700\u5c0f\u5806\u5373\u53ef\u3002<\/p>\n<p>&nbsp;<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre> 1 #include &lt;iostream&gt;\r\n 2 #include &lt;queue&gt;\r\n 3 \r\n 4 using namespace std;\r\n 5 \r\n 6 int main()\r\n 7 {\r\n 8     priority_queue&lt;int ,vector&lt;int&gt;,greater&lt;int&gt; &gt; q;\r\n 9     int n;\r\n10     int num;\r\n11     cin &gt;&gt; n;\r\n12     while(n--)\r\n13     {\r\n14         cin &gt;&gt; num;\r\n15         q.push(num);\r\n16     }\r\n17 \r\n18     long long sum = 0;\r\n19     \r\n20     while(!q.empty())\r\n21     {\r\n22         int num1 = q.top();\r\n23         q.pop();\r\n24         int num2 = q.top();\r\n25         q.pop();\r\n26         sum += num1 + num2;\r\n27         if(q.empty())\r\n28             break;\r\n29         q.push(num1 + num2);\r\n30     }\r\n31     \r\n32     cout &lt;&lt; sum &lt;&lt; endl;\r\n33     return 0;\r\n34 }<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740 &nbsp; 1. \u54c8\u592b\u66fc\u6811\u4e5f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[119],"class_list":["post-4020","post","type-post","status-publish","format-standard","hentry","tag-03-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/4020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=4020"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/4020\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=4020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=4020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=4020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}