{"id":1166,"date":"2024-08-31T09:00:00","date_gmt":"2024-08-31T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1166"},"modified":"2024-08-15T12:44:46","modified_gmt":"2024-08-15T04:44:46","slug":"zerojudge-a219","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-a219\/","title":{"rendered":"ZeroJudge A219: \u9650\u5236\u6392\u5217"},"content":{"rendered":"\n\n\n<p>\u5c0f\u5149\u7684 DFS \u526a\u679d\u6280\u5de7\u5728\u9019\u500b\u6691\u5047\u9032\u6b65\u4e86\u4e00\u4e9b\u4e9b\uff0c\u4f46\u662f\u4ecd\u7136\u7121\u6cd5\u901a\u904e DP \u7684\u5669\u5922\u3002\u73fe\u5728\u7d66\u4f60 N \u500b\u4eba\uff0c\u7de8\u865f\u5206\u5225\u662f A\u3001B\u3001\u2026\u3001Z\uff0c\u63a5\u8457\u7e3d\u662f\u6703\u6709\u4eba\u4e0d\u60f3\u6392\u54ea\u88e1\uff0c\u8acb\u4f60\u628a\u6240\u6709\u53ef\u80fd\u5217\u51fa\u4f86\uff0c\u4f46\u662f\u8f38\u51fa\u6a94\u96a8\u4fbf\u751f\u4e00\u751f\u5c31\u7206\u8868\u4e86\uff01\u56e0\u6b64\u5e0c\u671b\u4f60\u5982\u679c\u65b0\u7684\u6392\u5217\u8ddf\u4e0a\u6b21\u4e00\u6a23\u7684\u90e8\u5206\u5c31\u4e0d\u8f38\u51fa\u4e86\uff0c\u50c5\u50c5\u8f38\u51fa\u4e0d\u540c\u7684\u90e8\u5206\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u6709\u591a\u7b46\u6e2c\u8cc7\uff0c\u6bcf\u7b46\u7b2c\u4e00\u884c\u6709\u4e00\u500b\u6b63\u6574\u6578 N (1 \u2266 N \u2266 15)\u3002\u63a5\u4e0b\u4f86\u6703\u6709 N \u884c\uff0c\u7b2c N \u884c\u4ee3\u8868 \u7b2c N \u500b\u4eba\u4e0d\u60f3\u6392\u7684\u4f4d\u7f6e\uff0c\u4ee5 0 \u4ee3\u8868\u7d50\u675f\u3002<\/td><td>\u8acb\u628a\u6240\u6709\u53ef\u80fd\u5217\u51fa\u4f86(\u4f9d\u7167\u5b57\u5178\u9806\u5e8f)\uff0c\u8ddf\u4e0a\u6b21\u4e00\u6a23\u7684\u90e8\u5206\u5c31\u4e0d\u8f38\u51fa\uff0c\u50c5\u50c5\u8f38\u51fa\u4e0d\u540c\u7684\u90e8\u5206\u3002<\/td><\/tr><tr><td>3<br>0<br>0<br>0<br>3<br>1 0<br>3 0<br>0<\/td><td>ABC<br>CB<br>BAC<br>CA<br>CAB<br>BA<br><br>BAC<br>CA<br>CB<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u4f7f\u7528\u4e8c\u7dad\u9663\u5217\u7684\u5e03\u6797\u503c\u4f86\u7d00\u9304\u6bcf\u4e00\u500b\u4eba\u4e0d\u60f3\u8981\u88ab\u6392\u5728\u54ea\u88e1\uff0c\u4e26\u4e14\u4f7f\u7528 DFS \u4f86\u627e\u51fa\u6240\u6709\u7684\u53ef\u80fd\u6027\u3002\u5728\u8f38\u51fa\u6642\uff0c\u7d00\u9304\u4e0a\u4e00\u500b\u8981\u8f38\u51fa\u7684\u5b57\u4e32\uff0c\u548c\u76ee\u524d\u7684\u5b57\u4e32\u505a\u6bd4\u5c0d\uff0c\u53ea\u8981\u6709\u76f8\u540c\u7684\u5b57\u5143\u5c31\u8df3\u904e\uff0c\u88ab\u8a18\u9304\u7684\u5b57\u4e32\u90fd\u662f\u5b8c\u6574\u672a\u522a\u6e1b\u7684\u5b57\u4e32\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a219\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A219: \u9650\u5236\u6392\u5217<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nbool MAP[30][30] = {};\nint arr[26];\nint N, used[30] = {}, add[30] = {};\n\nvoid DFS(const int set) {\n    if (set == N) {\n        for (int i = 0; i&lt;set; i++) {\n            if(arr[i] == add[i]){\n                continue;\n            }\n            arr[i] = add[i];\n            cout &lt;&lt; char(&#39;A&#39;+ add[i]);\n        }\n        cout &lt;&lt; &quot;\\n&quot;;\n        return;\n    }\n    for (int i = 0; i&lt;N; i++) {\n        if (used[i] &gt; 0 || MAP[i][set+1]) continue;\n        add[set] = i;\n        used[i]++;\n        DFS(set+1);\n        used[i]--;\n        add[set] = -1;\n\n    }\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    for (int i = 0; i&lt;26; i++) {\n        used[i] = 0;\n        add[i] = -1;\n    }\n    while (cin &gt;&gt; N) {\n        for (int i = 0; i&lt;26; i++) {\n            for (int j = 0; j&lt;26; j++) {\n                MAP[i][j] = false;\n            }\n        }\n        for (int i = 0; i&lt;N; i++) {\n            int num;\n            arr[i] = -1;\n            while (cin &gt;&gt; num && num != 0) MAP[i][num] = true;\n        }\n        DFS(0);\n    }\n}\n\n\/\/ZeroJudge A219\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u5149\u7684 DFS \u526a\u679d\u6280\u5de7\u5728\u9019\u500b\u6691\u5047\u9032\u6b65\u4e86\u4e00\u4e9b\u4e9b\uff0c\u4f46\u662f\u4ecd\u7136\u7121\u6cd5\u901a\u904e DP \u7684\u5669\u5922\u3002\u73fe\u5728\u7d66\u4f60 N \u500b\u4eba\uff0c\u7de8\u865f\u5206\u5225\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[29],"tags":[21,22,8,11,34,9],"class_list":["post-1166","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-dfs","tag-22","tag-8","tag-11","tag-34","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/comments?post=1166"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1166\/revisions"}],"predecessor-version":[{"id":1167,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1166\/revisions\/1167"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=1166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=1166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=1166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}