{"id":349,"date":"2017-02-19T10:56:49","date_gmt":"2017-02-19T02:56:49","guid":{"rendered":"http:\/\/kylelv.com\/?p=349"},"modified":"2017-12-25T20:41:22","modified_gmt":"2017-12-25T12:41:22","slug":"bzoj-1231-usaco2008-novmixup2-%e6%b7%b7%e4%b9%b1%e7%9a%84%e5%a5%b6%e7%89%9b-%e7%8a%b6%e5%8e%8bdp","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=349","title":{"rendered":"bzoj 1231: [Usaco2008 Nov]mixup2 \u6df7\u4e71\u7684\u5976\u725b  &#8212; \u72b6\u538bDP"},"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-69fdef6cb71d7\" 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-69fdef6cb71d7\"  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=349\/#1231_Usaco2008_Novmixup2_%E6%B7%B7%E4%B9%B1%E7%9A%84%E5%A5%B6%E7%89%9B\" title=\"1231: [Usaco2008 Nov]mixup2 \u6df7\u4e71\u7684\u5976\u725b\">1231: [Usaco2008 Nov]mixup2 \u6df7\u4e71\u7684\u5976\u725b<\/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=349\/#Description\" title=\"Description\">Description<\/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=349\/#Input\" title=\"Input\">Input<\/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=349\/#Output\" title=\"Output\">Output<\/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=349\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/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=349\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=349\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"1231_Usaco2008_Novmixup2_%E6%B7%B7%E4%B9%B1%E7%9A%84%E5%A5%B6%E7%89%9B\"><\/span>1231: [Usaco2008 Nov]mixup2 \u6df7\u4e71\u7684\u5976\u725b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a010 Sec\u00a0\u00a0Memory Limit:\u00a0162 MB<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u6df7\u4e71\u7684\u5976\u725b [Don Piele, 2007] Farmer John\u7684N(4 &lt;= N &lt;= 16)\u5934\u5976\u725b\u4e2d\u7684\u6bcf\u4e00\u5934\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u7f16\u53f7S_i (1 &lt;= S_i &lt;= 25,000). \u5976\u725b\u4e3a\u5979\u4eec\u7684\u7f16\u53f7\u611f\u5230\u9a84\u50b2, \u6240\u4ee5\u6bcf\u4e00\u5934\u5976\u725b\u90fd\u628a\u5979\u7684\u7f16\u53f7\u523b\u5728\u4e00\u4e2a\u91d1\u724c\u4e0a, \u5e76\u4e14\u628a\u91d1\u724c\u6302\u5728\u5979\u4eec\u5bbd\u5927\u7684\u8116\u5b50\u4e0a. \u5976\u725b\u4eec\u5bf9\u5728\u6324\u5976\u7684\u65f6\u5019\u88ab\u6392\u6210\u4e00\u652f&#8221;\u6df7\u4e71&#8221;\u7684\u961f\u4f0d\u975e\u5e38\u53cd\u611f. \u5982\u679c\u4e00\u4e2a\u961f\u4f0d\u91cc\u4efb\u610f\u4e24\u5934\u76f8\u90bb\u7684\u5976\u725b\u7684\u7f16\u53f7\u76f8\u5dee\u8d85\u8fc7K (1 &lt;= K &lt;= 3400), \u5b83\u5c31\u88ab\u79f0\u4e3a\u662f\u6df7\u4e71\u7684. \u6bd4\u5982\u8bf4\uff0c\u5f53N = 6, K = 1\u65f6, 1, 3, 5, 2, 6, 4 \u5c31\u662f\u4e00\u652f&#8221;\u6df7\u4e71&#8221;\u7684\u961f\u4f0d, \u4f46\u662f 1, 3, 6, 5, 2, 4 \u4e0d\u662f(\u56e0\u4e3a5\u548c6\u53ea\u76f8\u5dee1). \u90a3\u4e48, \u6709\u591a\u5c11\u79cd\u80fd\u591f\u4f7f\u5976\u725b\u6392\u6210&#8221;\u6df7\u4e71&#8221;\u7684\u961f\u4f0d\u7684\u65b9\u6848\u5462?<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>* \u7b2c 1 \u884c: \u7528\u7a7a\u683c\u9694\u5f00\u7684\u4e24\u4e2a\u6574\u6570N\u548cK<\/p>\n<p>* \u7b2c 2..N+1 \u884c: \u7b2ci+1\u884c\u5305\u542b\u4e86\u4e00\u4e2a\u7528\u6765\u8868\u793a\u7b2ci\u5934\u5976\u725b\u7684\u7f16\u53f7\u7684\u6574\u6570: S_i<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u7b2c 1 \u884c: \u53ea\u6709\u4e00\u4e2a\u6574\u6570, \u8868\u793a\u6709\u591a\u5c11\u79cd\u80fd\u591f\u4f7f\u5976\u725b\u6392\u6210&#8221;\u6df7\u4e71&#8221;\u7684\u961f\u4f0d\u7684\u65b9\u6848. \u7b54\u6848\u4fdd\u8bc1\u662f \u4e00\u4e2a\u572864\u4f4d\u8303\u56f4\u5185\u7684\u6574\u6570.<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">4 1<br \/>\n3<br \/>\n4<br \/>\n2<br \/>\n1<br \/>\n<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p><span class=\"sampledata\">2<\/span><\/p>\n<p>\u8f93\u51fa\u89e3\u91ca:<\/p>\n<p>\u4e24\u79cd\u65b9\u6cd5\u5206\u522b\u662f:<br \/>\n3 1 4 2<br \/>\n2 4 1 3<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>&nbsp;<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;cstdio&gt;\r\n#include&lt;iostream&gt;\r\nusing namespace std;\r\n#define F(i,l,r) for(int i=l;i&lt;=r;i++)\r\n#define ll long long\r\ninline int read()\r\n{\r\n    int x=0;char ch=getchar();\r\n    while(ch&lt;'0'||ch&gt;'9') ch=getchar();\r\n    while(ch&gt;='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\r\n    return x;\r\n}\r\ninline int abs(int a){return a&gt;0?a:-a;}\r\nll f[20][1&lt;&lt;16],ans;\r\nint n,k,p[20],a[20],maxx;\r\nint main()\r\n{\r\n    n=read();k=read();maxx=(1&lt;&lt;n)-1;\r\n    F(i,1,n){a[i]=read();p[i]=1&lt;&lt;(n-i);}\r\n    F(i,1,n) f[i][p[i]]=1;\r\n    F(i,1,maxx) F(j,1,n)\r\n        if(p[j]&amp;i) F(h,1,n)\r\n            if((p[h]|i)!=i&amp;&amp;abs(a[h]-a[j])&gt;k)\r\n                f[h][p[h]|i]+=f[j][i];\r\n    F(i,1,n) ans+=f[i][maxx];\r\n    printf(\"%lld\\n\",ans); \r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1231: [Usaco2008 Nov]mixup2 \u6df7\u4e71\u7684\u5976\u725b Time Limit:\u00a010 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[5,30],"class_list":["post-349","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-dp"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/349","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=349"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/349\/revisions"}],"predecessor-version":[{"id":352,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/349\/revisions\/352"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}