{"id":49260,"date":"2024-12-02T12:35:22","date_gmt":"2024-12-02T04:35:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49260\/"},"modified":"2024-12-02T12:35:22","modified_gmt":"2024-12-02T04:35:22","slug":"%e7%9c%bc%e7%9d%9b%e9%94%ae%e7%9b%98","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49260\/","title":{"rendered":"\u773c\u775b\u952e\u76d8"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u773c\u775b\u952e\u76d8<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u773c\u775b\u952e\u76d8\u300b<\/span>\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/173226842467405188472ea.jpg\" class=\"aligncenter\" title=\"\u773c\u775b\u952e\u76d8\u63d2\u56fe\" alt=\"\u773c\u775b\u952e\u76d8\u63d2\u56fe\" \/><\/p>\n<p>650\u3002 2\u952e\u952e\u76d8<\/p>\n<p><strong>\u96be\u5ea6\uff1a<\/strong>\u4e2d\u7b49<\/p>\n<p><strong>\u4e3b\u9898\uff1a<\/strong>\u6570\u5b66\uff0c\u52a8\u6001\u89c4\u5212<\/p>\n<p>\u8bb0\u4e8b\u672c\u7684\u5c4f\u5e55\u4e0a\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\u201ca\u201d\u3002\u6bcf\u4e00\u6b65\u60a8\u90fd\u53ef\u4ee5\u5728\u6b64\u8bb0\u4e8b\u672c\u4e0a\u6267\u884c\u4ee5\u4e0b\u4e24\u4e2a\u64cd\u4f5c\u4e4b\u4e00\uff1a<\/p>\n<ul>\n<li>\u5168\u90e8\u590d\u5236\uff1a\u60a8\u53ef\u4ee5\u590d\u5236\u5c4f\u5e55\u4e0a\u51fa\u73b0\u7684\u6240\u6709\u5b57\u7b26\uff08\u4e0d\u5141\u8bb8\u90e8\u5206\u590d\u5236\uff09\u3002<\/li>\n<li>\u7c98\u8d34\uff1a\u53ef\u4ee5\u7c98\u8d34\u4e0a\u6b21\u590d\u5236\u7684\u5b57\u7b26\u3002<\/li>\n<\/ul>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570n\uff0c\u8fd4\u56de<em>\u5728\u5c4f\u5e55\u4e0a\u7cbe\u786e\u51fa\u73b0n\u6b21\u5b57\u7b26\u201ca\u201d\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570<\/em>.<\/p>\n<p><strong>\u793a\u4f8b1\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u8f93\u5165\uff1a<\/strong>n = 3<\/li>\n<li> <strong>\u8f93\u51fa\uff1a<\/strong> 3<\/li>\n<li> <strong>\u8bf4\u660e\uff1a<\/strong> \u4e00\u5f00\u59cb\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u5b57\u7b26\u201ca\u201d\u3002\n<ul>\n<li>\u7b2c1\u6b65\uff0c\u6211\u4eec\u4f7f\u7528copy all\u64cd\u4f5c\u3002<\/li>\n<li>\u7b2c2\u6b65\uff0c\u6211\u4eec\u4f7f\u7528\u7c98\u8d34\u64cd\u4f5c\u5f97\u5230&#8217;aa&#8217;\u3002<\/li>\n<li>\u7b2c3\u6b65\uff0c\u6211\u4eec\u4f7f\u7528\u7c98\u8d34\u64cd\u4f5c\u5f97\u5230&#8217;aaa&#8217;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b2\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u8f93\u5165\uff1a<\/strong>n = 1<\/li>\n<li> <strong>\u8f93\u51fa\uff1a<\/strong> 0<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b3\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u8f93\u5165\uff1a<\/strong>n = 10<\/li>\n<li> <strong>\u8f93\u51fa\uff1a<\/strong>7<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b2\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u8f93\u5165\uff1a<\/strong>n = 24<\/li>\n<li> <strong>\u8f93\u51fa\uff1a<\/strong> 9<\/li>\n<\/ul>\n<p><strong>\u9650\u5236\uff1a<\/strong><\/p>\n<ul>\n<li>1 &lt;=n &lt;=1000<\/li>\n<\/ul>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ol>\n<li>\u5982\u679cn = 3\uff0c\u6700\u540e\u4e00\u6b65\u526a\u8d34\u677f\u4e2d\u53ef\u80fd\u6709\u591a\u5c11\u4e2a\u5b57\u7b26\uff1f n = 7\uff1f n = 10\uff1f n = 24\uff1f<\/li>\n<\/ol>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u6211\u4eec\u9700\u8981\u627e\u5230\u6700\u5c11\u7684\u64cd\u4f5c\u6b21\u6570\u624d\u80fd\u5728\u5c4f\u5e55\u4e0a\u7cbe\u786e\u663e\u793a n \u4e2a\u5b57\u7b26\u201ca\u201d\u3002\u6211\u4eec\u5c06\u4f7f\u7528\u52a8\u6001\u7f16\u7a0b\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<ol>\n<li>\n<p><strong>\u7406\u89e3\u95ee\u9898\uff1a<\/strong><\/p>\n<ul>\n<li>\u6211\u4eec\u4ece\u5c4f\u5e55\u4e0a\u7684\u4e00\u4e2a\u201ca\u201d\u5f00\u59cb\u3002<\/li>\n<li>\u6211\u4eec\u53ef\u4ee5\u201c\u5168\u90e8\u590d\u5236\u201d\uff08\u590d\u5236\u5f53\u524d\u5c4f\u5e55\u5185\u5bb9\uff09\u6216\u201c\u7c98\u8d34\u201d\uff08\u7c98\u8d34\u4e0a\u6b21\u590d\u5236\u7684\u5185\u5bb9\uff09\u3002<\/li>\n<li>\u6211\u4eec\u9700\u8981\u786e\u5b9a\u5c4f\u5e55\u4e0a\u6b63\u597d\u6709n\u4e2a\u5b57\u7b26\u201ca\u201d\u6240\u9700\u7684\u6700\u5c11\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u52a8\u6001\u89c4\u5212\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u52a8\u6001\u7f16\u7a0b\uff08dp\uff09\u6570\u7ec4 dp\uff0c\u5176\u4e2d dp[i] \u8868\u793a\u5728\u5c4f\u5e55\u4e0a\u7cbe\u786e\u83b7\u53d6 i \u4e2a\u5b57\u7b26\u6240\u9700\u7684\u6700\u5c11\u64cd\u4f5c\u6570\u3002<\/li>\n<li>\u521d\u59cb\u5316 dp[1] = 0\uff0c\u56e0\u4e3a\u9700\u8981 0 \u6b21\u64cd\u4f5c\u624d\u80fd\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u4e00\u4e2a\u201ca\u201d\u3002<\/li>\n<li>\u5bf9\u4e8e\u4ece2\u5230n\u7684\u6bcf\u4e2a\u5b57\u7b26i\uff0c\u901a\u8fc7\u68c0\u67e5i\u7684\u6bcf\u4e2a\u9664\u6570\u6765\u8ba1\u7b97\u6700\u5c11\u7684\u64cd\u4f5c\u3002\u5982\u679c i \u80fd\u88ab d \u6574\u9664\uff0c\u5219\uff1a\n<ul>\n<li>\u5230\u8fbei\u6240\u9700\u7684\u8fd0\u7b97\u6b21\u6570\u662f\u5230\u8fbed\u6240\u9700\u7684\u8fd0\u7b97\u52a0\u4e0ad\u76f8\u4e58\u5f97\u5230i\u6240\u9700\u7684\u8fd0\u7b97\u4e4b\u548c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u89e3\u51b3\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ul>\n<li>\u7528inf\uff08\u6216\u4e00\u4e2a\u5927\u6570\u5b57\uff09\u521d\u59cb\u5316\u4e00\u4e2adp\u6570\u7ec4\uff0c\u9664\u4e86dp[1]\u4e4b\u5916\u7684\u6240\u6709\u503c\u3002<\/li>\n<li>\u5bf9\u4e8e\u4ece 2 \u5230 n \u7684\u6bcf\u4e2a i\uff0c\u8fed\u4ee3 i \u7684\u53ef\u80fd\u7ea6\u6570\uff0c\u5e76\u6839\u636e\u901a\u8fc7\u590d\u5236\u548c\u7c98\u8d34\u8fbe\u5230 i \u6240\u9700\u7684\u64cd\u4f5c\u66f4\u65b0 dp[i]\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>650\u3002 2\u952e\u952e\u76d8<\/strong><\/p>\n<pre>&lt;?php\n\/\/ Example usage\necho minOperations(3); \/\/ Output: 3\necho minOperations(1); \/\/ Output: 0\necho minOperations(10) . \"\\n\"; \/\/ Output: 7\necho minOperations(24) . \"\\n\"; \/\/ Output: 9\n?&gt;\n<\/pre>\n<h3> \u89e3\u91ca\uff1a <\/h3>\n<ul>\n<li> <strong>\u521d\u59cb\u5316\uff1a<\/strong> dp \u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u5f88\u5927\u7684\u6570\u5b57\uff08php_int_max\uff09\uff0c\u8868\u793a\u6700\u521d\u4e0d\u53ef\u8fbe\u7684\u72b6\u6001\u3002<\/li>\n<li> <strong>\u9664\u6570\u68c0\u67e5\uff1a<\/strong>\u5bf9\u4e8e\u6bcf\u4e2a\u6570\u5b57i\uff0c\u68c0\u67e5\u6240\u6709\u9664\u6570d\u3002\u901a\u8fc7\u8003\u8651\u5230\u8fbe d \u6240\u9700\u7684\u64cd\u4f5c\uff0c\u7136\u540e\u4e58\u4ee5\u5f97\u5230 i \u6765\u66f4\u65b0 dp[i]\u3002<\/li>\n<li> <strong>\u8f93\u51fa\uff1a<\/strong>\u7ed3\u679c\u662fdp[n]\u7684\u503c\uff0c\u5b83\u7ed9\u51fa\u4e86\u5728\u5c4f\u5e55\u4e0a\u7cbe\u786e\u83b7\u53d6n\u4e2a\u5b57\u7b26\u6240\u9700\u7684\u6700\u5c11\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u786e\u4fdd\u6211\u4eec\u9488\u5bf9\u7ed9\u5b9a\u7684\u7ea6\u675f\u6709\u6548\u5730\u8ba1\u7b97\u6700\u5c11\u7684\u64cd\u4f5c\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>repository<\/strong> \u4e00\u4e2a star \u6216\u5728\u60a8\u6700\u559c\u6b22\u7684\u793e\u4ea4\u7f51\u7edc\u4e0a\u5206\u4eab\u8be5\u5e16\u5b50?\u3002\u4f60\u4eec\u7684\u652f\u6301\u5bf9\u6211\u6765\u8bf4\u610f\u4e49\u91cd\u5927\uff01<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u8981\u66f4\u591a\u8fd9\u6837\u6709\u7528\u7684\u5185\u5bb9\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff1a<\/p>\n<ul>\n<li><strong>linkedin<\/strong><\/li>\n<li><strong>github<\/strong><\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/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>\u773c\u775b\u952e\u76d8 \u6536\u85cf \u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587\u300a\u773c\u775b\u952e\u76d8\u300b\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0\u6587\u7ae0\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01 650\u3002 2\u952e\u952e\u76d8 \u96be\u5ea6\uff1a\u4e2d\u7b49 \u4e3b\u9898\uff1a\u6570\u5b66\uff0c\u52a8\u6001\u89c4\u5212 \u8bb0\u4e8b\u672c\u7684\u5c4f\u5e55\u4e0a\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\u201ca\u201d\u3002\u6bcf\u4e00\u6b65\u60a8\u90fd\u53ef\u4ee5\u5728\u6b64\u8bb0\u4e8b\u672c\u4e0a\u6267\u884c\u4ee5\u4e0b\u4e24\u4e2a\u64cd\u4f5c\u4e4b\u4e00\uff1a \u5168\u90e8\u590d\u5236\uff1a\u60a8\u53ef\u4ee5\u590d\u5236\u5c4f\u5e55\u4e0a\u51fa\u73b0\u7684\u6240\u6709\u5b57\u7b26\uff08\u4e0d\u5141\u8bb8\u90e8\u5206\u590d\u5236\uff09\u3002 \u7c98\u8d34\uff1a\u53ef\u4ee5\u7c98\u8d34\u4e0a\u6b21\u590d\u5236\u7684\u5b57\u7b26\u3002 \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570n\uff0c\u8fd4\u56de\u5728\u5c4f\u5e55\u4e0a\u7cbe\u786e\u51fa\u73b0n\u6b21\u5b57\u7b26\u201ca\u201d\u7684\u6700\u5c11\u64cd\u4f5c\u6b21\u6570. \u793a\u4f8b1\uff1a \u8f93\u5165\uff1an = 3 \u8f93\u51fa\uff1a 3 \u8bf4\u660e\uff1a \u4e00\u5f00\u59cb\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u5b57\u7b26\u201ca\u201d\u3002 \u7b2c1\u6b65\uff0c\u6211\u4eec\u4f7f\u7528copy all\u64cd\u4f5c\u3002 \u7b2c2\u6b65\uff0c\u6211\u4eec\u4f7f\u7528\u7c98\u8d34\u64cd\u4f5c\u5f97\u5230&#8217;aa&#8217;\u3002 \u7b2c3\u6b65\uff0c\u6211\u4eec\u4f7f\u7528\u7c98\u8d34\u64cd\u4f5c\u5f97\u5230&#8217;aaa&#8217;\u3002 \u793a\u4f8b2\uff1a \u8f93\u5165\uff1an = 1 \u8f93\u51fa\uff1a 0 \u793a\u4f8b3\uff1a \u8f93\u5165\uff1an = 10 \u8f93\u51fa\uff1a7 \u793a\u4f8b2\uff1a \u8f93\u5165\uff1an = 24 \u8f93\u51fa\uff1a 9 \u9650\u5236\uff1a 1 &lt;=n &lt;=1000 \u63d0\u793a\uff1a \u5982\u679cn = 3\uff0c\u6700\u540e\u4e00\u6b65\u526a\u8d34\u677f\u4e2d\u53ef\u80fd\u6709\u591a\u5c11\u4e2a\u5b57\u7b26\uff1f n = 7\uff1f n = 10\uff1f n [&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-49260","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49260","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=49260"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49260\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}