{"id":1264,"date":"2024-11-16T09:00:00","date_gmt":"2024-11-16T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1264"},"modified":"2024-10-19T12:35:14","modified_gmt":"2024-10-19T04:35:14","slug":"zerojudge-a364","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-a364\/","title":{"rendered":"ZeroJudge A364: \u795e\u79d8\u7684\u9032\u4f4d\u554f\u984c"},"content":{"rendered":"\n<p>\u5728\u4e00\u500b\u795e\u79d8\u7684\u570b\u5bb6\uff0c\u4ed6\u5011\u6709\u4e0d\u540c\u7684\u6587\u660e\uff0c\u4ed6\u5011\u6240\u4f7f\u7528\u7684\u6578\u5b57\u8868\u793a\u6cd5\u8ddf\u5e38\u898b\u7684 \u5341\u9032\u4f4d\u6cd5\u4e0d\u4e00\u6a23\u3002\u5c0d\u65bc\u4e00\u500b\u5341\u9032\u4f4d\u7684\u6578\u5b57 N\uff0c\u4ed6\u5011\u6703\u8868\u793a\u6210 abc\uff0c\u5176\u4e2d a > b > c >= 0 \uff0c\u4e14\u6eff\u8db3 N= C(a, 3) + C(b, 2) + C(c, 1) \uff0c C \u70ba\u4e8c\u9805\u4fc2\u6578\uff0c\u5373 C(m, n) = m!\/(n!(m-n)!)\uff0c\u4f46\u7576 m &lt; n \u6642\uff0cC(m, n) = 0\u3002\u70ba\u5e6b\u52a9\u4e86\u89e3\u9019\u500b\u795e\u79d8\u570b\u5ea6\u7684\u6587\u5316\uff0c \u8acb\u5beb\u4e00\u7a0b\u5f0f\u4f86\u5c07\u5341\u9032\u4f4d\u6578\u8f49\u63db\u6210\u9019\u500b\u795e\u79d8\u7684\u9032\u4f4d\u6cd5\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>\u7b2c\u4e00\u884c\u6709\u4e00\u500b\u6574\u6578 m\uff0c1 \u2264 m \u2264 10\uff0c\u4ee3\u8868\u8981\u8f49\u63db\u7684\u5341\u9032\u4f4d\u6578\u7684\u500b\u6578\u3002\u63a5\u4e0b\u4f86\u7684 m \u884c\uff08\u7b2c 2 \u884c\u81f3\u7b2c (m+1) \u884c\uff09\uff1a\u6bcf\u4e00\u884c\u90fd\u6709\u4e00\u500b\u4ecb\u65bc 0 \u548c 500 \u4e4b\u9593\u7684\u6574\u6578\uff0c\u4ee3\u8868\u8981\u8f49\u63db\u7684\u5341\u9032\u4f4d\u6578\u3002<\/td><td>\u91dd\u5c0d\u6bcf\u4e00\u500b\u5341\u9032\u4f4d\u6578\u5206\u5225\u5728\u4e00\u884c\u8f38\u51fa\u5c0d\u61c9\u7684 abc\uff0c\u5176\u9593\u4e0d\u9700\u7559\u7a7a\u767d\uff0c\u6ce8\u610f a\u3001 b \u548c c \u672a\u5fc5\u662f\u53ea\u6709\u4e00\u4f4d\u6578\uff0c\u82e5\u7b54\u6848\u4e0d\u552f\u4e00\u6642\u8acb\u8f38\u51fa\u5b57\u5178\u9806\u5e8f\u6700\u5c0f\u7684\u8868\u793a\u6cd5\uff0c\u5373\u76e1 \u53ef\u80fd\u53d6\u5c0f\u7684 a \u53ca b \u503c\u3002<\/td><\/tr><tr><td>4<br>0<br>1<br>2<br>200<\/td><td>210<br>310<br>320<br>1187<\/td><\/tr><tr><td>3<br>18<br>19<br>20<\/td><td>542<br>543<br>610<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge A364 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u53ef\u4ee5\u4f7f\u7528 DFS \u4f86\u8dd1\u6240\u6709\u53ef\u80fd\uff0c\u5305\u62ec\u53ea\u589e\u52a0\u5176\u4e2d\u4e00\u500b\u6578\u5b57\u6216\u662f\u5169\u500b\u6578\u5b57\u6216\u662f\u5168\u90e8\u90fd\u52a0\uff0c\u4f46\u662f\u9700\u8981\u78ba\u4fdd a > b > c\uff0c\u6240\u4ee5\u4e00\u958b\u59cb\u5728\u547c\u53eb DFS \u6642\uff0ca = 2\u3001b = 1\u3001c = 0\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a364\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A364: \u795e\u79d8\u7684\u9032\u4f4d\u554f\u984c<\/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 ok = false;\n\nint calc (const int a, const int b) {\n    if (a &lt; b) return 0;\n    int result = 1, divisor = 1;;\n    for (int i = 0; i&lt;b; i++) {\n        result *= a-i;\n        divisor *= i+1;\n    }\n    return result\/divisor;\n}\n\nint cCalc(const int A, const int B, const int C) {\n    return calc(A, 3) + calc(B, 2) + calc(C, 1);\n}\n\nvoid DFS(const int A, const int B, const int C, const int target) {\n    if (ok) return;\n    const int result = cCalc(A, B, C);\n    if (result &gt; target) return;\n    if (result == target) {\n        cout &lt;&lt; A &lt;&lt; B &lt;&lt; C &lt;&lt; endl;\n        ok = true;\n        return;\n    }\n    if (A+1 &gt; B && B &gt; C) DFS(A+1, B, C, target);\n    if (A &gt; B+1 && B+1 &gt; C) DFS(A, B+1, C, target);\n    if (A &gt; B && B &gt; C+1) DFS(A, B, C+1, target);\n    if (A+1 &gt; B+1 && B+1 &gt; C) DFS(A+1, B+1, C, target);\n    if (A &gt; B+1 && B+1 &gt; C+1) DFS(A, B+1, C+1, target);\n    if (A+1 &gt; B && B &gt; C+1) DFS(A+1, B, C+1, target);\n    DFS(A+1, B+1, C+1, target);\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int M;\n    cin &gt;&gt; M;\n    for (int i = 0; i &lt; M; i++) {\n        int N;\n        cin &gt;&gt; N;\n        ok = false;\n        DFS(2, 1, 0, N);\n    }\n}\n\n\/\/ZeroJudge A364\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e00\u500b\u795e\u79d8\u7684\u570b\u5bb6\uff0c\u4ed6\u5011\u6709\u4e0d\u540c\u7684\u6587\u660e\uff0c\u4ed6\u5011\u6240\u4f7f\u7528\u7684\u6578\u5b57\u8868\u793a\u6cd5\u8ddf\u5e38\u898b\u7684 \u5341\u9032\u4f4d\u6cd5\u4e0d\u4e00\u6a23\u3002\u5c0d\u65bc\u4e00\u500b\u5341\u9032\u4f4d\u7684\u6578\u5b57 N\uff0c [&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,8,34,13,9],"class_list":["post-1264","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-dfs","tag-8","tag-34","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1264","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=1264"}],"version-history":[{"count":3,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1264\/revisions"}],"predecessor-version":[{"id":1267,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1264\/revisions\/1267"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=1264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=1264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=1264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}