{"id":6032,"date":"2024-04-18T00:06:39","date_gmt":"2024-04-17T16:06:39","guid":{"rendered":"http:\/\/zyg.luchers.cn\/?p=6032"},"modified":"2024-04-18T00:06:39","modified_gmt":"2024-04-17T16:06:39","slug":"%e5%9b%9e%e6%ba%af%e7%ae%97%e6%b3%95%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"http:\/\/zyg.luchers.cn\/index.php\/2024\/04\/18\/%e5%9b%9e%e6%ba%af%e7%ae%97%e6%b3%95%e5%9f%ba%e7%a1%80\/","title":{"rendered":"\u56de\u6eaf\u7b97\u6cd5\u57fa\u7840"},"content":{"rendered":"<h1>\u56de\u6eaf\u7b97\u6cd5<\/h1>\n<h2>1\u3001\u7406\u8bba\u77e5\u8bc6<\/h2>\n<h3>1\u3001\u4ec0\u4e48\u662f\u56de\u6eaf\u6cd5<\/h3>\n<p>1\u3001\u56de\u6eaf\u6cd5\u4e5f\u53ef\u4ee5\u53eb\u505a\u56de\u6eaf\u641c\u7d22\u6cd5\uff0c\u5b83\u662f\u4e00\u79cd\u641c\u7d22\u7684\u65b9\u5f0f\u3002<\/p>\n<p>2\u3001\u5728\u4e8c\u53c9\u6811\u7cfb\u5217\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u4e0d\u6b62\u4e00\u6b21\uff0c\u63d0\u5230\u4e86\u56de\u6eaf\uff0c\u4f8b\u5982<a href=\"https:\/\/programmercarl.com\/\u4e8c\u53c9\u6811\u4e2d\u9012\u5f52\u5e26\u7740\u56de\u6eaf.html\">\u4e8c\u53c9\u6811\uff1a\u4ee5\u4e3a\u4f7f\u7528\u4e86\u9012\u5f52\uff0c\u5176\u5b9e\u8fd8\u9690\u85cf\u7740\u56de\u6eaf (opens new window)<\/a>\u3002<\/p>\n<p>3\u3001\u56de\u6eaf\u662f\u9012\u5f52\u7684\u526f\u4ea7\u54c1\uff0c\u53ea\u8981\u6709\u9012\u5f52\u5c31\u4f1a\u6709\u56de\u6eaf\u3002<\/p>\n<p>4\u3001<strong>\u6240\u4ee5\u4ee5\u4e0b\u8bb2\u89e3\u4e2d\uff0c\u56de\u6eaf\u51fd\u6570\u4e5f\u5c31\u662f\u9012\u5f52\u51fd\u6570\uff0c\u6307\u7684\u90fd\u662f\u4e00\u4e2a\u51fd\u6570<\/strong>\u3002<\/p>\n<h3>2\u3001\u56de\u6eaf\u6cd5\u7684\u6548\u7387<\/h3>\n<p>1\u3001\u56de\u6eaf\u6cd5\u7684\u6027\u80fd\u5982\u4f55\u5462\uff0c\u8fd9\u91cc\u8981\u548c\u5927\u5bb6\u8bf4\u6e05\u695a\u4e86\uff0c<strong>\u867d\u7136\u56de\u6eaf\u6cd5\u5f88\u96be\uff0c\u5f88\u4e0d\u597d\u7406\u89e3\uff0c\u4f46\u662f\u56de\u6eaf\u6cd5\u5e76\u4e0d\u662f\u4ec0\u4e48\u9ad8\u6548\u7684\u7b97\u6cd5<\/strong>\u3002<\/p>\n<p>2\u3001<strong>\u56e0\u4e3a\u56de\u6eaf\u7684\u672c\u8d28\u662f\u7a77\u4e3e\uff0c\u7a77\u4e3e\u6240\u6709\u53ef\u80fd\uff0c\u7136\u540e\u9009\u51fa\u6211\u4eec\u60f3\u8981\u7684\u7b54\u6848<\/strong>\uff0c\u5982\u679c\u60f3\u8ba9\u56de\u6eaf\u6cd5\u9ad8\u6548\u4e00\u4e9b\uff0c\u53ef\u4ee5\u52a0\u4e00\u4e9b\u526a\u679d\u7684\u64cd\u4f5c\uff0c\u4f46\u4e5f\u6539\u4e0d\u4e86\u56de\u6eaf\u6cd5\u5c31\u662f\u7a77\u4e3e\u7684\u672c\u8d28\u3002<\/p>\n<p>3\u3001\u90a3\u4e48\u65e2\u7136\u56de\u6eaf\u6cd5\u5e76\u4e0d\u9ad8\u6548\u4e3a\u4ec0\u4e48\u8fd8\u8981\u7528\u5b83\u5462\uff1f<\/p>\n<p>4\u3001\u56e0\u4e3a\u6ca1\u5f97\u9009\uff0c\u4e00\u4e9b\u95ee\u9898\u80fd\u66b4\u529b\u641c\u51fa\u6765\u5c31\u4e0d\u9519\u4e86\uff0c\u6491\u6b7b\u4e86\u518d\u526a\u679d\u4e00\u4e0b\uff0c\u8fd8\u6ca1\u6709\u66f4\u9ad8\u6548\u7684\u89e3\u6cd5\u3002<\/p>\n<p>5\u3001\u6b64\u65f6\u5927\u5bb6\u5e94\u8be5\u597d\u5947\u4e86\uff0c\u90fd\u4ec0\u4e48\u95ee\u9898\uff0c\u8fd9\u4e48\u725b\u903c\uff0c\u53ea\u80fd\u66b4\u529b\u641c\u7d22\u3002<\/p>\n<h3>3\u3001\u56de\u6eaf\u6cd5\u89e3\u51b3\u7684\u95ee\u9898<\/h3>\n<p>1\u3001\u56de\u6eaf\u6cd5\uff0c\u4e00\u822c\u53ef\u4ee5\u89e3\u51b3\u5982\u4e0b\u51e0\u79cd\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u7ec4\u5408\u95ee\u9898\uff1aN\u4e2a\u6570\u91cc\u9762\u6309\u4e00\u5b9a\u89c4\u5219\u627e\u51fak\u4e2a\u6570\u7684\u96c6\u5408<\/li>\n<li>\u5207\u5272\u95ee\u9898\uff1a\u4e00\u4e2a\u5b57\u7b26\u4e32\u6309\u4e00\u5b9a\u89c4\u5219\u6709\u51e0\u79cd\u5207\u5272\u65b9\u5f0f<\/li>\n<li>\u5b50\u96c6\u95ee\u9898\uff1a\u4e00\u4e2aN\u4e2a\u6570\u7684\u96c6\u5408\u91cc\u6709\u591a\u5c11\u7b26\u5408\u6761\u4ef6\u7684\u5b50\u96c6<\/li>\n<li>\u6392\u5217\u95ee\u9898\uff1aN\u4e2a\u6570\u6309\u4e00\u5b9a\u89c4\u5219\u5168\u6392\u5217\uff0c\u6709\u51e0\u79cd\u6392\u5217\u65b9\u5f0f<\/li>\n<li>\u68cb\u76d8\u95ee\u9898\uff1aN\u7687\u540e\uff0c\u89e3\u6570\u72ec\u7b49\u7b49<\/li>\n<\/ul>\n<p>2\u3001<strong>\u76f8\u4fe1\u5927\u5bb6\u770b\u7740\u8fd9\u4e9b\u4e4b\u540e\u4f1a\u53d1\u73b0\uff0c\u6bcf\u4e2a\u95ee\u9898\uff0c\u90fd\u4e0d\u7b80\u5355\uff01<\/strong><\/p>\n<p>1\u3001\u53e6\u5916\uff0c\u4f1a\u6709\u4e00\u4e9b\u540c\u5b66\u53ef\u80fd\u5206\u4e0d\u6e05\u4ec0\u4e48\u662f\u7ec4\u5408\uff0c\u4ec0\u4e48\u662f\u6392\u5217\uff1f<\/p>\n<p>2\u3001<strong>\u7ec4\u5408\u662f\u4e0d\u5f3a\u8c03\u5143\u7d20\u987a\u5e8f\u7684\uff0c\u6392\u5217\u662f\u5f3a\u8c03\u5143\u7d20\u987a\u5e8f<\/strong>\u3002<\/p>\n<p>3\u3001\u4f8b\u5982\uff1a{1, 2} \u548c {2, 1} \u5728\u7ec4\u5408\u4e0a\uff0c\u5c31\u662f\u4e00\u4e2a\u96c6\u5408\uff0c\u56e0\u4e3a\u4e0d\u5f3a\u8c03\u987a\u5e8f\uff0c\u800c\u8981\u662f\u6392\u5217\u7684\u8bdd\uff0c{1, 2} \u548c {2, 1} \u5c31\u662f\u4e24\u4e2a\u96c6\u5408\u4e86\u3002<\/p>\n<p>4\u3001\u8bb0\u4f4f\u7ec4\u5408\u65e0\u5e8f\uff0c\u6392\u5217\u6709\u5e8f\uff0c\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<h3>4\u3001\u5982\u4f55\u7406\u89e3\u56de\u6eaf\u6cd5<\/h3>\n<p><strong>\u56de\u6eaf\u6cd5\u89e3\u51b3\u7684\u95ee\u9898\u90fd\u53ef\u4ee5\u62bd\u8c61\u4e3a\u6811\u5f62\u7ed3\u6784<\/strong>\uff0c\u662f\u7684\uff0c\u6211\u6307\u7684\u662f\u6240\u6709\u56de\u6eaf\u6cd5\u7684\u95ee\u9898\u90fd\u53ef\u4ee5\u62bd\u8c61\u4e3a\u6811\u5f62\u7ed3\u6784\uff01<\/p>\n<p>\u56e0\u4e3a\u56de\u6eaf\u6cd5\u89e3\u51b3\u7684\u90fd\u662f\u5728\u96c6\u5408\u4e2d\u9012\u5f52\u67e5\u627e\u5b50\u96c6\uff0c<strong>\u96c6\u5408\u7684\u5927\u5c0f\u5c31\u6784\u6210\u4e86\u6811\u7684\u5bbd\u5ea6\uff0c\u9012\u5f52\u7684\u6df1\u5ea6\uff0c\u90fd\u6784\u6210\u7684\u6811\u7684\u6df1\u5ea6<\/strong>\u3002<\/p>\n<p>\u9012\u5f52\u5c31\u8981\u6709\u7ec8\u6b62\u6761\u4ef6\uff0c\u6240\u4ee5\u5fc5\u7136\u662f\u4e00\u68f5\u9ad8\u5ea6\u6709\u9650\u7684\u6811\uff08N\u53c9\u6811\uff09\u3002<\/p>\n<p>\u8fd9\u5757\u53ef\u80fd\u521d\u5b66\u8005\u8fd8\u4e0d\u592a\u7406\u89e3\uff0c\u540e\u9762\u7684\u56de\u6eaf\u7b97\u6cd5\u89e3\u51b3\u7684\u6240\u6709\u9898\u76ee\u4e2d\uff0c\u6211\u90fd\u4f1a\u5f3a\u8c03\u8fd9\u4e00\u70b9\u5e76\u753b\u56fe\u4e3e\u76f8\u5e94\u7684\u4f8b\u5b50\uff0c\u73b0\u5728\u6709\u4e00\u4e2a\u5370\u8c61\u5c31\u884c\u3002<\/p>\n<h2>2\u3001\u56de\u6eaf\u4e09\u90e8\u66f2<\/h2>\n<p>1\u3001\u56de\u6eaf\u7b97\u6cd5\u6a21\u677f\u8fd4\u56de\u503c\u4ee5\u53ca\u53c2\u6570<\/p>\n<ul>\n<li>\u4e00\u822c\u8fd4\u56de\u503c\u662fvoid<\/li>\n<li>\u53c2\u6570\u5c31\u9700\u8981\u6839\u636e\u903b\u8f91\u6765<\/li>\n<\/ul>\n<p>2\u3001\u56de\u6eaf\u7b97\u6cd5\u7684\u7ec8\u6b62\u6761\u4ef6<\/p>\n<ul>\n<li>\n<pre><code class=\"language-text\">if (\u7ec8\u6b62\u6761\u4ef6) {\n  \u5b58\u653e\u7ed3\u679c;\n  return;\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>3\u3001\u56de\u6eaf\u641c\u7d22\u7684\u904d\u5386\u8fc7\u7a0b<\/p>\n<ul>\n<li>\n<pre><code class=\"language-text\">for (\u9009\u62e9\uff1a\u672c\u5c42\u96c6\u5408\u4e2d\u5143\u7d20\uff08\u6811\u4e2d\u8282\u70b9\u5b69\u5b50\u7684\u6570\u91cf\u5c31\u662f\u96c6\u5408\u7684\u5927\u5c0f\uff09) {\n  \u5904\u7406\u8282\u70b9;\n  backtracking(\u8def\u5f84\uff0c\u9009\u62e9\u5217\u8868); \/\/ \u9012\u5f52\n  \u56de\u6eaf\uff0c\u64a4\u9500\u5904\u7406\u7ed3\u679c\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>3\u3001\u56de\u6eaf\u7b97\u6cd5\u6a21\u677f\u6846\u67b6\u56fe<\/h2>\n<pre><code>void backtracking(\u53c2\u6570) {\n    if (\u7ec8\u6b62\u6761\u4ef6) {\n        \u5b58\u653e\u7ed3\u679c;\n        return;\n    }\n\n    for (\u9009\u62e9\uff1a\u672c\u5c42\u96c6\u5408\u4e2d\u5143\u7d20\uff08\u6811\u4e2d\u8282\u70b9\u5b69\u5b50\u7684\u6570\u91cf\u5c31\u662f\u96c6\u5408\u7684\u5927\u5c0f\uff09) {\n        \u5904\u7406\u8282\u70b9;\n        backtracking(\u8def\u5f84\uff0c\u9009\u62e9\u5217\u8868); \/\/ \u9012\u5f52\n        \u56de\u6eaf\uff0c\u64a4\u9500\u5904\u7406\u7ed3\u679c\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u56de\u6eaf\u7b97\u6cd5 1\u3001\u7406\u8bba\u77e5\u8bc6 1\u3001\u4ec0\u4e48\u662f\u56de\u6eaf\u6cd5 1\u3001\u56de\u6eaf\u6cd5\u4e5f\u53ef\u4ee5\u53eb\u505a\u56de\u6eaf\u641c\u7d22\u6cd5\uff0c\u5b83\u662f\u4e00\u79cd\u641c\u7d22\u7684\u65b9\u5f0f\u3002 2\u3001\u5728\u4e8c\u53c9\u6811\u7cfb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-6032","post","type-post","status-publish","format-standard","hentry","category-31"],"_links":{"self":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/6032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/comments?post=6032"}],"version-history":[{"count":1,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/6032\/revisions"}],"predecessor-version":[{"id":6033,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/6032\/revisions\/6033"}],"wp:attachment":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6032"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}