{"id":230,"date":"2016-11-04T09:26:24","date_gmt":"2016-11-04T01:26:24","guid":{"rendered":"http:\/\/kylelv.com\/?p=230"},"modified":"2017-12-13T12:54:38","modified_gmt":"2017-12-13T04:54:38","slug":"usaco-2-2-2subset-sums-%e9%9b%86%e5%90%88","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=230","title":{"rendered":"usaco-2.2.2Subset Sums \u96c6\u5408"},"content":{"rendered":"<p>&nbsp;<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fdef75a6b30\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fdef75a6b30\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.kylelv.com\/?p=230\/#usaco-222Subset_Sums_%E9%9B%86%E5%90%88\" title=\"usaco-2.2.2Subset Sums \u96c6\u5408\">usaco-2.2.2Subset Sums \u96c6\u5408<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=230\/#%E9%A2%98%E7%9B%AE%E6%8F%8F%E8%BF%B0\" title=\"\u9898\u76ee\u63cf\u8ff0\">\u9898\u76ee\u63cf\u8ff0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=230\/#%E8%BE%93%E5%85%A5\" title=\"\u8f93\u5165\">\u8f93\u5165<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=230\/#%E8%BE%93%E5%87%BA\" title=\"\u8f93\u51fa\">\u8f93\u51fa<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=230\/#%E6%A0%B7%E4%BE%8B%E8%BE%93%E5%85%A5\" title=\"\u6837\u4f8b\u8f93\u5165\">\u6837\u4f8b\u8f93\u5165<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=230\/#%E6%A0%B7%E4%BE%8B%E8%BE%93%E5%87%BA\" title=\"\u6837\u4f8b\u8f93\u51fa\">\u6837\u4f8b\u8f93\u51fa<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=230\/#01%E8%83%8C%E5%8C%85%EF%BC%8C%E5%AF%B9%E6%AF%8F%E4%B8%AA%E6%95%B0%E8%87%B3%E5%A4%9A%E5%8F%96%E4%B8%80%E6%AC%A1%EF%BC%8C%E4%B8%BA%E4%BA%86%E9%81%BF%E5%85%8D%E9%87%8D%E5%A4%8D%EF%BC%8C%E5%BA%94%E5%80%92%E5%BA%8Fdp\" title=\"01\u80cc\u5305\uff0c\u5bf9\u6bcf\u4e2a\u6570\u81f3\u591a\u53d6\u4e00\u6b21\uff0c\u4e3a\u4e86\u907f\u514d\u91cd\u590d\uff0c\u5e94\u5012\u5e8fdp\">01\u80cc\u5305\uff0c\u5bf9\u6bcf\u4e2a\u6570\u81f3\u591a\u53d6\u4e00\u6b21\uff0c\u4e3a\u4e86\u907f\u514d\u91cd\u590d\uff0c\u5e94\u5012\u5e8fdp<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"usaco-222Subset_Sums_%E9%9B%86%E5%90%88\"><\/span>usaco-2.2.2Subset Sums \u96c6\u5408<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\">\u65f6\u95f4\u9650\u5236: 1 Sec\u00a0\u00a0\u5185\u5b58\u9650\u5236: 128 MB<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E9%A2%98%E7%9B%AE%E6%8F%8F%E8%BF%B0\"><\/span>\u9898\u76ee\u63cf\u8ff0<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p align=\"left\">\u5bf9\u4e8e\u4ece1\u5230N\u7684\u8fde\u7eed\u6574\u96c6\u5408\u5408\uff0c\u80fd\u5212\u5206\u6210\u4e24\u4e2a\u5b50\u96c6\u5408\uff0c\u4e14\u4fdd\u8bc1\u6bcf\u4e2a\u96c6\u5408\u7684\u6570\u5b57\u548c\u662f\u76f8\u7b49\u7684\u3002<br \/>\n\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679cN=3\uff0c\u5bf9\u4e8e{1\uff0c2\uff0c3}\u80fd\u5212\u5206\u6210\u4e24\u4e2a\u5b50\u96c6\u5408\uff0c\u4ed6\u4eec\u6bcf\u4e2a\u7684\u6240\u6709\u6570\u5b57\u548c\u662f\u76f8\u7b49\u7684\uff1a<\/p>\n<ul>\n<li>{3} and {1,2}<\/li>\n<\/ul>\n<p align=\"left\">\u8fd9\u662f\u552f\u4e00\u4e00\u79cd\u5206\u53d1\uff08\u4ea4\u6362\u96c6\u5408\u4f4d\u7f6e\u88ab\u8ba4\u4e3a\u662f\u540c\u4e00\u79cd\u5212\u5206\u65b9\u6848\uff0c\u56e0\u6b64\u4e0d\u4f1a\u589e\u52a0\u5212\u5206\u65b9\u6848\u603b\u6570\uff09<br \/>\n\u5982\u679cN=7\uff0c\u6709\u56db\u79cd\u65b9\u6cd5\u80fd\u5212\u5206\u96c6\u5408{1\uff0c2\uff0c3\uff0c4\uff0c5\uff0c6\uff0c7}\uff0c\u6bcf\u4e00\u79cd\u5206\u53d1\u7684\u5b50\u96c6\u5408\u5404\u6570\u5b57\u548c\u662f\u76f8\u7b49\u7684:<\/p>\n<ul>\n<li>{1,6,7} and {2,3,4,5} {\u6ce8 1+6+7=2+3+4+5}<\/li>\n<li>{2,5,7} and {1,3,4,6}<\/li>\n<li>{3,4,7} and {1,2,5,6}<\/li>\n<li>{1,2,4,7} and {3,5,6}<\/li>\n<\/ul>\n<p>\u7ed9\u51faN\uff0c\u4f60\u7684\u7a0b\u5e8f\u5e94\u8be5\u8f93\u51fa\u5212\u5206\u65b9\u6848\u603b\u6570\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u5212\u5206\u65b9\u6848\uff0c\u5219\u8f93\u51fa0\u3002\u7a0b\u5e8f\u4e0d\u80fd\u9884\u5b58\u7ed3\u679c\u76f4\u63a5\u8f93\u51fa\u3002<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E8%BE%93%E5%85%A5\"><\/span>\u8f93\u5165<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p align=\"left\">\u8f93\u5165\u6587\u4ef6\u53ea\u6709\u4e00\u884c\uff0c\u4e14\u53ea\u6709\u4e00\u4e2a\u6574\u6570N<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E8%BE%93%E5%87%BA\"><\/span>\u8f93\u51fa<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p align=\"left\">\u8f93\u51fa\u5212\u5206\u65b9\u6848\u603b\u6570\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219\u8f93\u51fa0\u3002<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E6%A0%B7%E4%BE%8B%E8%BE%93%E5%85%A5\"><\/span>\u6837\u4f8b\u8f93\u5165<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre class=\"content\">7<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"%E6%A0%B7%E4%BE%8B%E8%BE%93%E5%87%BA\"><\/span>\u6837\u4f8b\u8f93\u51fa<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre class=\"content\">4<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"01%E8%83%8C%E5%8C%85%EF%BC%8C%E5%AF%B9%E6%AF%8F%E4%B8%AA%E6%95%B0%E8%87%B3%E5%A4%9A%E5%8F%96%E4%B8%80%E6%AC%A1%EF%BC%8C%E4%B8%BA%E4%BA%86%E9%81%BF%E5%85%8D%E9%87%8D%E5%A4%8D%EF%BC%8C%E5%BA%94%E5%80%92%E5%BA%8Fdp\"><\/span>01\u80cc\u5305\uff0c\u5bf9\u6bcf\u4e2a\u6570\u81f3\u591a\u53d6\u4e00\u6b21\uff0c\u4e3a\u4e86\u907f\u514d\u91cd\u590d\uff0c\u5e94\u5012\u5e8fdp<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre class=\"lang:c++ decode:true \">#include&lt;cstdio&gt;\r\n#define ll long long\r\nll n,ji,dp[10010];\r\nint main()\r\n{\r\n    scanf(\"%lld\",&amp;n);\r\n    ji=n*(n+1)\/2;\r\n    if(ji%2){printf(\"0\");return 0;}\r\n    ji&gt;&gt;=1;dp[0]=1;\r\n    for(ll i=1;i&lt;=n;i++) for(ll j=ji;j&gt;=i;j--) dp[j]+=dp[j-i];\r\n    printf(\"%lld\",dp[ji]\/2);\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; usaco-2.2.2Subset Sums \u96c6\u5408 \u65f6\u95f4\u9650\u5236: 1 Sec\u00a0\u00a0\u5185\u5b58\u9650\u5236: 128 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9,5],"class_list":["post-230","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-9","tag-dp"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=230"}],"version-history":[{"count":5,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions"}],"predecessor-version":[{"id":246,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions\/246"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}