{"id":399,"date":"2018-01-01T20:50:26","date_gmt":"2018-01-01T12:50:26","guid":{"rendered":"http:\/\/kylelv.com\/?p=399"},"modified":"2018-01-01T20:50:38","modified_gmt":"2018-01-01T12:50:38","slug":"bzoj-1531-poi2005bank-notes-%e8%83%8c%e5%8c%85dp","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=399","title":{"rendered":"bzoj 1531: [POI2005]Bank notes  &#8212; \u80cc\u5305dp"},"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-69fdef88826fa\" 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-69fdef88826fa\"  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=399\/#1531_POI2005Bank_notes\" title=\"1531: [POI2005]Bank notes\">1531: [POI2005]Bank notes<\/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=399\/#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=399\/#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=399\/#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=399\/#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=399\/#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=399\/#HINT\" title=\"HINT\">HINT<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.kylelv.com\/?p=399\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"1531_POI2005Bank_notes\"><\/span>1531: [POI2005]Bank notes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a0<\/span>5 Sec\u00a0\u00a0<span class=\"green\">Memory Limit:\u00a0<\/span>64 MB<\/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>Byteotian Bit Bank (BBB) \u62e5\u6709\u4e00\u5957\u5148\u8fdb\u7684\u8d27\u5e01\u7cfb\u7edf,\u8fd9\u4e2a\u7cfb\u7edf\u4e00\u5171\u6709n\u79cd\u9762\u503c\u7684\u786c\u5e01,\u9762\u503c\u5206\u522b\u4e3ab1, b2,&#8230;, bn. \u4f46\u662f\u6bcf\u79cd\u786c\u5e01\u6709\u6570\u91cf\u9650\u5236,\u73b0\u5728\u6211\u4eec\u60f3\u8981\u51d1\u51fa\u9762\u503ck\u6c42\u6700\u5c11\u8981\u7528\u591a\u5c11\u4e2a\u786c\u5e01.<\/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\u4e00\u884c\u4e00\u4e2a\u6570 n, 1 &lt;= n &lt;= 200. \u63a5\u4e0b\u6765\u4e00\u884c n \u4e2a\u6574\u6570b1, b2,&#8230;, bn, 1 &lt;= b1 &lt; b2 &lt; &#8230; &lt; b n &lt;= 20 000, \u7b2c\u4e09\u884c n \u4e2a\u6574\u6570c1, c2,&#8230;, cn, 1 &lt;= ci &lt;= 20 000, \u8868\u793a\u6bcf\u79cd\u786c\u5e01\u7684\u4e2a\u6570.\u6700\u540e\u4e00\u884c\u4e00\u4e2a\u6570k \u2013 \u8868\u793a\u8981\u51d1\u7684\u9762\u503c\u6570\u91cf, 1 &lt;= k &lt;= 20 000.<\/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\u4e00\u884c\u4e00\u4e2a\u6570\u8868\u793a\u6700\u5c11\u9700\u8981\u4ed8\u7684\u786c\u5e01\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\">3<br \/>\n2 3 5<br \/>\n2 2 1<br \/>\n10<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\"><span class=\"sampledata\">3<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u65b0\u5e74\u7b2c\u4e00\u53d1~~<\/p>\n<p>\u7ed3\u679cWA\u597d\u51e0\u6b21\u3002\u3002<\/p>\n<p>\u5b66\u4e60\u4e86\u591a\u91cd\u80cc\u5305\u7684\u6b63\u786e\u59ff\u52bf<\/p>\n<p>\u7528\u5355\u8c03\u961f\u5217\u4f18\u5316\u505a\u5230O(nV)<\/p>\n<p>\u5141\u8bb8\u6211\u8f6c\u4e00\u53d1\u5927\u4f6c\u7684\u535a\u5ba2 <a href=\"http:\/\/lvat2000.is-programmer.com\/posts\/185588.html\" target=\"_blank\" rel=\"noopener\">http:\/\/lvat2000.is-programmer.com\/posts\/185588.html<\/a><\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;map&gt;\r\n#include&lt;cmath&gt;\r\n#include&lt;queue&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;cstring&gt;\r\n#include&lt;iostream&gt;\r\n#include&lt;algorithm&gt;\r\nusing namespace std;\r\n#define inf 1000000007\r\n#define ll long long\r\n#define N 20010\r\ninline int rd()\r\n{\r\n\tint x=0,f=1;char ch=getchar();\r\n\twhile(ch&lt;'0'||ch&gt;'9'){if(ch=='-')f=-1;ch=getchar();}\r\n\twhile(ch&gt;='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\r\n\treturn x*f;\r\n}\r\nint n,K,b[220],c[220];\r\nint q[N],f[2][N],ans=inf;\r\nint main()\r\n{\r\n\tn=rd();\r\n\tfor(int i=1;i&lt;=n;i++) b[i]=rd();\r\n\tfor(int i=1;i&lt;=n;i++) c[i]=rd();\r\n\tK=rd();\r\n\tmemset(f,0x3f,sizeof(f));f[0][0]=0;\r\n\tint l,r,x=0,lst=1;\r\n\tfor(int i=1;i&lt;=n;i++)\r\n\t{\r\n\t\tx^=1;lst^=1;\r\n\t\tfor(int j=0;j&lt;b[i];j++)\r\n\t\t{\r\n\t\t\tl=r=1;q[1]=0;\r\n\t\t\tfor(int k=0;k*b[i]+j&lt;=K;k++)\r\n\t\t\t{\r\n\t\t\t\twhile(l&lt;=r&amp;&amp;k-q[l]&gt;c[i]) l++;\r\n\t\t\t\tf[x][k*b[i]+j]=min(f[lst][k*b[i]+j],f[lst][q[l]*b[i]+j]+k-q[l]);\r\n\t\t\t\twhile(l&lt;=r&amp;&amp;(f[lst][q[r]*b[i]+j]+k-q[r]&gt;f[lst][k*b[i]+j])) r--;\r\n\t\t\t\tq[++r]=k;\r\n\t\t\t}\r\n\t\t}\r\n\t\tans=min(ans,f[x][K]);\r\n\t}\r\n\tprintf(\"%d\\n\",ans);\r\n\treturn 0;\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1531: [POI2005]Bank notes Time Limit:\u00a05 Sec\u00a0\u00a0Mem [&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,39],"class_list":["post-399","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-dp","tag-39"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/399","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=399"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/399\/revisions"}],"predecessor-version":[{"id":401,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/399\/revisions\/401"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}