{"id":49182,"date":"2024-12-02T14:24:36","date_gmt":"2024-12-02T06:24:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49182\/"},"modified":"2024-12-02T14:24:36","modified_gmt":"2024-12-02T06:24:36","slug":"%e7%9f%b3%e5%a4%b4%e6%b8%b8%e6%88%8fii","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49182\/","title":{"rendered":"\u77f3\u5934\u6e38\u620fII"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u77f3\u5934\u6e38\u620fII<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u77f3\u5934\u6e38\u620fII\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241115\/17316528276736ecdb5cf57.jpg\" class=\"aligncenter\" title=\"\u77f3\u5934\u6e38\u620fII\u63d2\u56fe\" alt=\"\u77f3\u5934\u6e38\u620fII\u63d2\u56fe\" \/><\/p>\n<p>1140\u3002\u77f3\u5934\u6e38\u620fii<\/p>\n<p><strong>\u96be\u5ea6\uff1a<\/strong>\u4e2d\u7b49<\/p>\n<p><strong>\u4e3b\u9898\uff1a<\/strong> \u6570\u7ec4\u3001\u6570\u5b66\u3001\u52a8\u6001\u89c4\u5212\u3001\u524d\u7f00\u548c\u3001\u535a\u5f08\u8bba<\/p>\n<p>\u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u7ee7\u7eed\u73a9\u77f3\u5934\u5806\u6e38\u620f\u3002 \u6709\u8bb8\u591a\u5806<strong>\u6392\u6210\u4e00\u6392<\/strong>\uff0c\u6bcf\u5806\u6709\u6b63\u6574\u6570\u4e2a\u77f3\u5b50piles[i]\u3002 \u6e38\u620f\u7684\u76ee\u6807\u662f\u4ee5\u6700\u591a\u7684\u77f3\u5b50\u7ed3\u675f\u3002<\/p>\n<p>\u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u8f6e\u6d41\uff0c\u7231\u4e3d\u4e1d\u5148\u5f00\u59cb\u3002 \u6700\u521d\uff0cm = 1.<\/p>\n<p>\u5728\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u4e2d\uff0c\u8be5\u73a9\u5bb6\u53ef\u4ee5\u62ff\u8d70<strong>\u7b2c\u4e00\u4e2a<\/strong>\u5269\u4f59 x \u5806\u4e2d\u7684<strong>\u6240\u6709\u77f3\u5934<\/strong>\uff0c\u5176\u4e2d 1 &lt;= x &lt;= 2m\u3002 \u7136\u540e\uff0c\u6211\u4eec\u8bbe\u7f6e m = max(m, x).<\/p>\n<p>\u6e38\u620f\u7ee7\u7eed\u8fdb\u884c\uff0c\u76f4\u5230\u6240\u6709\u7684\u77f3\u5b50\u90fd\u88ab\u62ff\u8d70\u3002<\/p>\n<p>\u5047\u8bbe\u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u53d1\u6325\u6700\u4f73\uff0c\u8fd4\u56de<em>\u7231\u4e3d\u4e1d\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u77f3\u5934\u6570\u91cf<\/em>\u3002<\/p>\n<p><strong>\u793a\u4f8b1\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u8f93\u5165\uff1a<\/strong> \u6869 = [2,7,9,4,4]<\/li>\n<li> <strong>\u8f93\u51fa\uff1a<\/strong> 10<\/li>\n<li> <strong>\u89e3\u91ca\uff1a<\/strong> \u5982\u679c alice \u4e00\u5f00\u59cb\u62ff\u4e86\u4e00\u5806\uff0cbob \u62ff\u4e86\u4e24\u5806\uff0c\u7136\u540e alice \u53c8\u62ff\u4e86 2 \u5806\u3002\u7231\u4e3d\u4e1d\u603b\u5171\u53ef\u4ee5\u83b7\u5f97 2 + 4 + 4 = 10 \u5806\u3002\u5982\u679c\u7231\u4e3d\u4e1d\u4e00\u5f00\u59cb\u62ff\u4e86\u4e24\u5806\uff0c\u90a3\u4e48\u9c8d\u52c3\u5c31\u53ef\u4ee5\u62ff\u8d70\u5269\u4e0b\u7684\u4e09\u5806\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u7231\u4e3d\u4e1d\u603b\u5171\u5f97\u5230 2 + 7 = 9 \u5806\u3002\u6240\u4ee5\u6211\u4eec\u8fd4\u56de 10\uff0c\u56e0\u4e3a\u5b83\u66f4\u5927\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b2\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u8f93\u5165\uff1a<\/strong> \u6869 = [1,2,3,4,5,100]<\/li>\n<li> <strong>\u8f93\u51fa\uff1a<\/strong> 104<\/li>\n<\/ul>\n<p><strong>\u9650\u5236\uff1a<\/strong><\/p>\n<ul>\n<li>1 &lt;= \u6869.\u957f\u5ea6 &lt;= 100<\/li>\n<li>1 &lt;= \u4e00\u5806[i] &lt;= 10<sup>4<\/sup><\/li>\n<\/ul>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ol>\n<li>\u4f7f\u7528\u52a8\u6001\u89c4\u5212\uff1a\u5bf9\u4e8e\u7ed9\u5b9a m \u7684piles[i:] \u7684\u7b54\u6848\uff0c\u72b6\u6001\u4e3a (i, m)\u3002<\/li>\n<\/ol>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u6211\u4eec\u9700\u8981\u4f7f\u7528\u52a8\u6001\u89c4\u5212\u6765\u627e\u5230\u5982\u679c\u53cc\u65b9\u90fd\u53d1\u6325\u6700\u4f73\u72b6\u6001\uff0calice \u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u77f3\u5934\u6570\u91cf\u3002\u4ee5\u4e0b\u662f\u5f00\u53d1\u89e3\u51b3\u65b9\u6848\u7684\u5206\u6b65\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u5b9a\u4e49\u72b6\u6001\u548c\u8f6c\u6362\uff1a<\/strong><\/p>\n<ul>\n<li>\u5b9a\u4e49\u4e00\u4e2a 2d dp \u6570\u7ec4\uff0c\u5176\u4e2d dp[i][m] \u8868\u793a alice \u4ece\u7b2c i \u5806\u5f00\u59cb\u53ef\u4ee5\u6536\u96c6\u7684\u6700\u5927\u77f3\u5934\uff0c\u6700\u5927\u62fe\u53d6\u9650\u5236\u4e3a m\u3002<\/li>\n<li>\u4f7f\u7528\u524d\u7f00\u548c\u6570\u7ec4\u6765\u9ad8\u6548\u8ba1\u7b97\u5b50\u6570\u7ec4\u4e2d\u77f3\u5934\u7684\u603b\u548c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u57fa\u672c\u6848\u4f8b\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u6ca1\u6709\u5269\u4e0b\u7684\u77f3\u5934\u53ef\u4f9b\u91c7\u6458\uff0c\u5219\u5f97\u5206\u4e3a 0\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9012\u5f52\u6848\u4f8b\uff1a<\/strong><\/p>\n<ul>\n<li>\u5bf9\u4e8e\u6bcf\u4e00\u5806 i \u548c\u6700\u5927\u5141\u8bb8\u62fe\u53d6 m \uff0c\u901a\u8fc7\u8003\u8651\u6240\u6709\u53ef\u80fd\u7684\u79fb\u52a8\uff08\u53d6 1 \u5230 2m \u5806\uff09\u6765\u8ba1\u7b97 alice \u53ef\u4ee5\u6536\u96c6\u7684\u6700\u5927\u77f3\u5934\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8f6c\u6362\u51fd\u6570\uff1a<\/strong><\/p>\n<ul>\n<li>\u5bf9\u4e8e\u7231\u4e3d\u4e1d\u53ef\u4ee5\u6311\u9009\u7684\u6bcf\u79cd\u53ef\u80fd\u7684\u5806\u6570\uff0c\u8ba1\u7b97\u7231\u4e3d\u4e1d\u53ef\u4ee5\u83b7\u5f97\u7684\u77f3\u5934\u603b\u6570\uff0c\u5e76\u4f7f\u7528\u672a\u6765\u72b6\u6001\u7684\u7ed3\u679c\u6765\u51b3\u5b9a\u6700\u4f73\u79fb\u52a8\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u8ba9\u6211\u4eec\u7528 php \u5b9e\u73b0\u8fd9\u4e2a\u89e3\u51b3\u65b9\u6848\uff1a<strong>1140\u3002\u77f3\u5934\u6e38\u620fii<\/strong><\/p>\n<pre>&lt;?php\n\/\/ Example usage\n$solution = new Solution();\n$piles1 = [2, 7, 9, 4, 4];\n$piles2 = [1, 2, 3, 4, 5, 100];\necho $solution-&gt;stoneGameII($piles1) . \"\\n\"; \/\/ Output: 10\necho $solution-&gt;stoneGameII($piles2) . \"\\n\"; \/\/ Output: 104\n?&gt;\n<\/pre>\n<h3> \u89e3\u91ca\uff1a <\/h3>\n<ol>\n<li> <strong>\u524d\u7f00\u603b\u548c\u8ba1\u7b97\uff1a<\/strong>\u8fd9\u6709\u52a9\u4e8e\u5feb\u901f\u8ba1\u7b97\u4efb\u610f\u4e00\u5806 i \u5230 j \u4e2d\u7684\u77f3\u5b50\u7684\u603b\u548c\u3002<\/li>\n<li> <strong>dp \u6570\u7ec4\u521d\u59cb\u5316\uff1a<\/strong> dp[i][m] \u4fdd\u5b58 alice \u4ece i \u5806\u5f00\u59cb\u53ef\u4ee5\u83b7\u53d6\u7684\u6700\u5927\u77f3\u5934\uff0c\u6700\u5927\u62fe\u53d6\u9650\u5236\u4e3a m\u3002<\/li>\n<li> <strong>\u52a8\u6001\u7f16\u7a0b\u8f6c\u6362\uff1a<\/strong> \u5bf9\u4e8e\u6bcf\u4e00\u5806\u548c m\uff0c\u901a\u8fc7\u8fed\u4ee3\u5979\u53ef\u4ee5\u83b7\u53d6\u7684\u53ef\u80fd\u5806\u6570\u5e76\u76f8\u5e94\u66f4\u65b0 dp \u6570\u7ec4\u6765\u8ba1\u7b97 alice \u53ef\u4ee5\u6536\u96c6\u7684\u6700\u5927\u77f3\u5934\u3002<\/li>\n<\/ol>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u786e\u4fdd\u4e86\u89e3\u51b3\u65b9\u6848\u7684\u9ad8\u6548\u8ba1\u7b97\uff0c\u5229\u7528\u52a8\u6001\u89c4\u5212\u6765\u907f\u514d\u5197\u4f59\u8ba1\u7b97\u3002<\/p>\n<p><strong>\u8054\u7cfb\u94fe\u63a5<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u53d1\u73b0\u672c\u7cfb\u5217\u6709\u5e2e\u52a9\uff0c\u8bf7\u8003\u8651\u5728 github \u4e0a\u7ed9<strong>\u5b58\u50a8\u5e93<\/strong> \u4e00\u9897\u661f\uff0c\u6216\u5728\u60a8\u6700\u559c\u6b22\u7684\u793e\u4ea4\u7f51\u7edc\u4e0a\u5206\u4eab\u8be5\u5e16\u5b50?\u3002\u60a8\u7684\u652f\u6301\u5bf9\u6211\u6765\u8bf4\u610f\u4e49\u91cd\u5927\uff01<\/p>\n<p>\u5982\u679c\u60a8\u60f3\u8981\u66f4\u591a\u7c7b\u4f3c\u7684\u6709\u7528\u5185\u5bb9\uff0c\u8bf7\u968f\u65f6\u5173\u6ce8\u6211\uff1a<\/p>\n<ul>\n<li><strong>\u9886\u82f1<\/strong><\/li>\n<li><strong>github<\/strong><\/li>\n<\/ul>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u77f3\u5934\u6e38\u620fII\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u77f3\u5934\u6e38\u620fII \u6536\u85cf \u5b66\u4e60\u6587\u7ae0\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0\u300a\u77f3\u5934\u6e38\u620fII\u300b\u5c06\u4f1a\u4ecb\u7ecd\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60\u6587\u7ae0\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01 1140\u3002\u77f3\u5934\u6e38\u620fii \u96be\u5ea6\uff1a\u4e2d\u7b49 \u4e3b\u9898\uff1a \u6570\u7ec4\u3001\u6570\u5b66\u3001\u52a8\u6001\u89c4\u5212\u3001\u524d\u7f00\u548c\u3001\u535a\u5f08\u8bba \u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u7ee7\u7eed\u73a9\u77f3\u5934\u5806\u6e38\u620f\u3002 \u6709\u8bb8\u591a\u5806\u6392\u6210\u4e00\u6392\uff0c\u6bcf\u5806\u6709\u6b63\u6574\u6570\u4e2a\u77f3\u5b50piles[i]\u3002 \u6e38\u620f\u7684\u76ee\u6807\u662f\u4ee5\u6700\u591a\u7684\u77f3\u5b50\u7ed3\u675f\u3002 \u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u8f6e\u6d41\uff0c\u7231\u4e3d\u4e1d\u5148\u5f00\u59cb\u3002 \u6700\u521d\uff0cm = 1. \u5728\u6bcf\u4e2a\u73a9\u5bb6\u7684\u56de\u5408\u4e2d\uff0c\u8be5\u73a9\u5bb6\u53ef\u4ee5\u62ff\u8d70\u7b2c\u4e00\u4e2a\u5269\u4f59 x \u5806\u4e2d\u7684\u6240\u6709\u77f3\u5934\uff0c\u5176\u4e2d 1 &lt;= x &lt;= 2m\u3002 \u7136\u540e\uff0c\u6211\u4eec\u8bbe\u7f6e m = max(m, x). \u6e38\u620f\u7ee7\u7eed\u8fdb\u884c\uff0c\u76f4\u5230\u6240\u6709\u7684\u77f3\u5b50\u90fd\u88ab\u62ff\u8d70\u3002 \u5047\u8bbe\u7231\u4e3d\u4e1d\u548c\u9c8d\u52c3\u53d1\u6325\u6700\u4f73\uff0c\u8fd4\u56de\u7231\u4e3d\u4e1d\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u77f3\u5934\u6570\u91cf\u3002 \u793a\u4f8b1\uff1a \u8f93\u5165\uff1a \u6869 = [2,7,9,4,4] \u8f93\u51fa\uff1a 10 \u89e3\u91ca\uff1a \u5982\u679c alice \u4e00\u5f00\u59cb\u62ff\u4e86\u4e00\u5806\uff0cbob \u62ff\u4e86\u4e24\u5806\uff0c\u7136\u540e alice \u53c8\u62ff\u4e86 2 \u5806\u3002\u7231\u4e3d\u4e1d\u603b\u5171\u53ef\u4ee5\u83b7\u5f97 2 + 4 + 4 = 10 \u5806\u3002\u5982\u679c\u7231\u4e3d\u4e1d\u4e00\u5f00\u59cb\u62ff\u4e86\u4e24\u5806\uff0c\u90a3\u4e48\u9c8d\u52c3\u5c31\u53ef\u4ee5\u62ff\u8d70\u5269\u4e0b\u7684\u4e09\u5806\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u7231\u4e3d\u4e1d\u603b\u5171\u5f97\u5230 2 + [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-49182","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=49182"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49182\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}