{"id":1227,"date":"2024-11-02T09:00:00","date_gmt":"2024-11-02T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1227"},"modified":"2024-09-30T11:23:28","modified_gmt":"2024-09-30T03:23:28","slug":"zerojudge-d577","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-d577\/","title":{"rendered":"ZeroJudge D577: Equivalent Head and Tail and Variations"},"content":{"rendered":"\n<p>\u5927\u5e2b\u5c08\u9580\u79d2\u6bba\u984c\u76ee\u7dad\u751f<\/p>\n\n\n\n<p>\u6709\u4e00\u5929\u4ed6\u79d2\u6bba\u4e86\u7b49\u503c\u9996\u5c3e\u548c\u5f8c\u6709\u4e86\u500b\u60f3\u6cd5<\/p>\n\n\n\n<p>\u5982\u679c\u6211\u5f9e\u524d\u9762\u4efb\u53d6 N \u500b\u6578\u628a\u5b83\u52a0\u8d77\u4f86<\/p>\n\n\n\n<p>\u90a3\u6703\u6709\u5e7e\u500b\u4e00\u6a23\u7684\u6578\u5b57\u5462<\/p>\n\n\n\n<p>\u53c8\u54ea\u500b\u6578\u5b57\u51fa\u73fe\u7684\u65b9\u6cd5\u6700\u591a\u5462<\/p>\n\n\n\n<p>\u4ed6\u8aaa\u9019\u5df2\u7d93\u8d85\u904e\u4ed6\u7684\u667a\u5546\u4e86<\/p>\n\n\n\n<p>\u65bc\u662f\u4ed6\u60f3\u627e\u6703\u7de8\u7a0b\u7684\u4eba\u5e6b\u4ed6\u7684\u5fd9<\/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>EOF \u8f38\u5165\uff0c\u7b2c 1 \u884c\u6709 2 \u500b\u6578\u5b57 a \u548c b (a \u4ee3\u8868\u6709\u5e7e\u500b\u6578\uff0cb \u4ee3\u8868\u8981\u53d6\u5e7e\u500b\u6578) (0&lt;=b&lt;=a&lt;=20)\u3002<br>\u63a5\u4e0b\u4f86\u6709 a \u500b\u6578\u5b57\u9019\u4e9b\u6578\u5b57\u548c\u4e0d\u8d85\u904e 2147483647 (\u4e0d\u4e00\u5b9a\u6392\u5e8f\u597d)\u3002<br>\u4ee5 a = b = 0 \u505a\u70ba\u7d50\u5c3e\u3002<\/td><td>\u8f38\u51fa 2 \u500b\u6578\u5b57 c \u548c d (c \u4ee3\u8868\u662f\u54ea\u500b\u6578\u5b57\u65b9\u6cd5\u6700\u591a\uff0cd \u4ee3\u8868\u65b9\u6cd5\u6578)\u3002<br>\u82e5\u6709\u5f88\u591a c \u5247\u8f38\u51fa\u6700\u5c0f\u90a3\u500b\u3002<\/td><\/tr><tr><td>10 2<br>1 2 3 4 5 6 7 8 9 10<br>5 3<br>1 2 3 4 5<br>0 0<\/td><td>11 5<br>8 2<\/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 DFS \u4f86\u7d2f\u52a0 b \u500b\u6578\u5b57\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\u5728 DFS \u4e2d\u9700\u8981\u5224\u65b7\u76ee\u524d\u8ff4\u5708\u8dd1\u5230\u7684\u6578\u5b57\u662f\u5426\u662f\u5728\u4e0a\u4e00\u500b\u6578\u5b57\u7684\u5f8c\u9762\uff0c\u6240\u4ee5\u53ef\u4ee5\u5728\u53c3\u6578\u4e2d\u518d\u5e36\u4e00\u500b start \u8b8a\u6578\u9810\u8a2d\u70ba 0\uff0c\u4e26\u4e14\u8ff4\u5708\u5f9e start \u958b\u59cb\uff0c\u7576\u8981\u518d\u6b21\u547c\u53eb DFS \u6642\uff0c\u5c07 start \u7684\u53c3\u6578\u6539\u6210 i+1\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528 Map \u4f86\u7d00\u9304\u6bcf\u4e00\u500b\u548c\u51fa\u73fe\u7684\u6b21\u6578\uff0c\u4e26\u4e14\u4f7f\u7528 for (auto it:Map) \u4f86\u5224\u65b7\u6700\u591a\u51fa\u73fe\u7684\u548c\u662f\u54ea\u4e00\u500b\uff0c\u6700\u5f8c\u8f38\u51fa\u7b54\u6848\u5373\u53ef\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=d577\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge D577: \u7b49\u503c\u9996\u5c3e\u548c\u8b8a\u5316\u578b<\/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;\n#include &lt;map&gt;\nusing namespace std;\n\nint a, b;\nint num[30] = {};\nbool visited[30] = {};\nmap&lt;int, int&gt;MAP;\n\nvoid DFS(const int count, const int add, const int start) {\n    if (count == b) {\n        MAP[add]++;\n    }\n    for (int i = start; i&lt;a; i++) {\n        if (!visited[i]) {\n            visited[i] = true;\n            DFS(count+1, add+num[i], i+1);\n            visited[i] = false;\n        }\n    }\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    while (cin &gt;&gt; a &gt;&gt; b && a != 0 && b != 0) {\n        MAP.clear();\n        for (int i = 0; i &lt; a; i++) {\n            cin &gt;&gt; num[i];\n            visited[i] = false;\n        }\n        DFS(0, 0, 0);\n        int max = -999, maxNum = 0;\n        for (auto it:MAP) {\n            if (it.second &gt; max) {\n                max = it.second;\n                maxNum = it.first;\n            }\n        }\n        cout &lt;&lt; maxNum &lt;&lt; &quot; &quot; &lt;&lt; max &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge D577\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5e2b\u5c08\u9580\u79d2\u6bba\u984c\u76ee\u7dad\u751f \u6709\u4e00\u5929\u4ed6\u79d2\u6bba\u4e86\u7b49\u503c\u9996\u5c3e\u548c\u5f8c\u6709\u4e86\u500b\u60f3\u6cd5 \u5982\u679c\u6211\u5f9e\u524d\u9762\u4efb\u53d6 N \u500b\u6578\u628a\u5b83\u52a0\u8d77\u4f86 \u90a3\u6703\u6709\u5e7e\u500b\u4e00 [&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,14,23,20,8,34,9],"class_list":["post-1227","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-dfs","tag-map","tag-pair","tag-20","tag-8","tag-34","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=1227"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1227\/revisions"}],"predecessor-version":[{"id":1228,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1227\/revisions\/1228"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}