{"id":1036,"date":"2024-08-04T09:00:00","date_gmt":"2024-08-04T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1036"},"modified":"2024-06-30T12:12:22","modified_gmt":"2024-06-30T04:12:22","slug":"zerojudge-b116","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-b116\/","title":{"rendered":"ZeroJudge B116: Plus and Minus"},"content":{"rendered":"\n\n\n<p>\u5047\u8a2d\u6709 N \u500b\u6b63\u6574\u6578 A[1], A[2], &#8230;, A[N]\uff0c\u6211\u5011\u8981\u5728\u6bcf\u4e00\u500b\u6578\u5b57\u4e4b\u524d\u52a0\u5165 + \u865f\u6216 &#8211; \u865f\u4f7f\u5f97\u5b83\u5011\u7684\u7e3d\u548c\u70ba 0\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a1\u30012\u30013\uff0c\u6211\u5011\u53ef\u4ee5\u5f97\u5230 (-1) + (-2) + (+3) = 0\uff1b\u4f46\u662f\u5c0d\u65bc 2\u30012\u30011 \u5247\u7121\u6cd5\u900f\u904e\u52a0\u5165 + \u865f\u6216 &#8211; \u865f\u4f7f\u5f97\u5b83\u5011\u7684\u7e3d\u548c\u70ba 0\u3002<\/p>\n\n\n\n<p>\u8acb\u4f60\u5beb\u4e00\u500b\u7a0b\u5f0f\u4f86\u5224\u65b7\u4efb\u610f N \u500b\u6b63\u6574\u6578\u662f\u5426\u53ef\u4ee5\u900f\u904e\u52a0\u5165 + \u865f\u6216 &#8211; \u865f\u4f7f\u5f97\u5b83\u5011\u7684\u7e3d\u548c\u70ba 0\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>\u8f38\u5165\u6a94\u7684\u7b2c\u4e00\u884c\u6709\u5169\u500b\u6b63\u6574\u6578, M\u53caN\u4ee5\u7a7a\u5340\u5206\uff0c\u4ee3\u8868\u6709M\u7d44\u3002\u6e2c\u8a66\u8cc7\u6599\uff0c\u6bcf\u4e00\u7d44\u6709N\u500b\u6b63\u6574\u6578\u3002<br>\u7b2c\u4e8c\u884c\u81f3\u7b2c M+1 \u884c\u5247\u5247\u5206\u5225\u8f38\u5165\u6240\u8a02\u5b9a\u7684 N \u500b\u6b63\u6574\u6578\uff0c\u4ee5\u7a7a\u767d\u5340\u5206\u3002\u5176\u4e2d 0 &lt; M &lt;= 10\uff0c\u4e14 0 &lt; N &lt;= 100\u3002<\/td><td>\u5c0d\u65bc\u6bcf\u4e00\u7d44\u6e2c\u8a66\u8cc7\u6599\uff0c\u82e5\u53ef\u4ee5\u627e\u5230\u52a0\u5165 + \u865f\u6216 &#8211; \u865f\u4f7f\u5f97\u5b83\u5011\u7684\u7e3d\u548c\u70ba 0 \u6642\uff0c\u8acb\u8f38\u51fa Yes\uff1b\u5426\u5247\u8acb\u8f38\u51fa No\u3002<\/td><\/tr><tr><td>4 3<br>1 2 3<br>3 2 1<br>2 2 2<br>5 1 6<br>2 8<br>1 2 3 4 5 6 7 8<br>12 12 10 11 34 22 33 26<\/td><td>Yes<br>Yes<br>No<br>Yes<br>Yes<br>Yes<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge B116 \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>\u672c\u984c\u5176\u5be6\u5c31\u662f\u8981\u627e\u5230\u5169\u500b\u76f8\u540c\u7684\u6578\u5b57\uff0c\u6240\u4ee5\u5982\u679c\u7e3d\u548c\u70ba\u5947\u6578\uff0c\u5247\u53ef\u4ee5\u76f4\u63a5\u8f38\u51fa\u300cNo\u300d\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528 DFS \u7684\u65b9\u5f0f\u628a\u6578\u5b57\u9032\u884c\u76f8\u52a0\u7aae\u8209\uff0c\u5982\u679c\u6709\u51fa\u73fe\u76f8\u52a0\u7684\u6578\u5b57\u662f\u7e3d\u548c\u7684\u4e00\u534a\u6642\uff0c\u4ee3\u8868\u53e6\u5916\u7684\u5176\u4ed6\u6578\u5b57\u76f8\u52a0\u4e5f\u6703\u8b8a\u6210\u7e3d\u548c\u7684\u4e00\u534a\uff0c\u6240\u4ee5\u76ee\u7684\u662f\u8981\u627e\u5230\u662f\u5426\u6709\u7d44\u5408\u53ef\u4ee5\u52a0\u5230\u7e3d\u5408\u7684\u4e00\u534a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=b116\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge B116: \u52a0\u6e1b\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;\n#include &lt;vector&gt;\nusing namespace std;\n\nbool ok = false;\nint sum = 0;\n\nvoid DFS(vector&lt;int&gt;num, int index, int count) {\n    if (ok || count &gt; sum\/2) return;\n    if (count == sum\/2) {\n        ok = true;\n        return;\n    }\n    if (index == num.size()) return;\n    for (int i = index; i&lt;num.size(); i++) {\n        DFS(num, index+1, count+num[i]);\n        if(ok) return;\n    }\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int M, N;\n    while (cin &gt;&gt; M &gt;&gt; N) {\n        for (int i = 0; i&lt;M; i++) {\n            vector&lt;int&gt;num;\n            int max = -999999;\n            sum = 0;\n            for (int j = 0; j&lt;N; j++) {\n                int tmp;\n                cin &gt;&gt; tmp;\n                sum += tmp;\n                if (tmp &gt; max) max = tmp;\n                num.push_back(tmp);\n            }\n            if (sum\/2 &lt; max || sum % 2 == 1) {\n                cout &lt;&lt; &quot;No\\n&quot;;\n                continue;\n            }\n            ok = false;\n            DFS(num, 0, 0);\n            if (ok) {\n                cout &lt;&lt; &quot;Yes\\n&quot;;\n                continue;\n            }\n            cout &lt;&lt; &quot;No\\n&quot;;\n        }\n    }\n}\n\n\/\/ZeroJudge B116\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5047\u8a2d\u6709 N \u500b\u6b63\u6574\u6578 A[1], A[2], &#8230;, A[N]\uff0c\u6211\u5011\u8981\u5728\u6bcf\u4e00\u500b\u6578\u5b57\u4e4b\u524d\u52a0\u5165 + \u865f\u6216 [&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":[25],"tags":[21,20,8,34,9],"class_list":["post-1036","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-dfs","tag-20","tag-8","tag-34","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1036","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=1036"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1036\/revisions"}],"predecessor-version":[{"id":1038,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1036\/revisions\/1038"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}