{"id":226,"date":"2016-10-18T19:17:24","date_gmt":"2016-10-18T11:17:24","guid":{"rendered":"http:\/\/kylelv.com\/?p=226"},"modified":"2017-12-13T12:55:43","modified_gmt":"2017-12-13T04:55:43","slug":"bzoj-3384-usaco2004-novapple-catching-%e6%8e%a5%e8%8b%b9%e6%9e%9c","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=226","title":{"rendered":"bzoj 3384: [Usaco2004 Nov]Apple Catching \u63a5\u82f9\u679c"},"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-69fdef74a7b4e\" 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-69fdef74a7b4e\"  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=226\/#3384_Usaco2004_NovApple_Catching_%E6%8E%A5%E8%8B%B9%E6%9E%9C\" title=\"3384: [Usaco2004 Nov]Apple Catching \u63a5\u82f9\u679c\">3384: [Usaco2004 Nov]Apple Catching \u63a5\u82f9\u679c<\/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=226\/#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=226\/#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=226\/#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=226\/#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=226\/#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=226\/#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=226\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"3384_Usaco2004_NovApple_Catching_%E6%8E%A5%E8%8B%B9%E6%9E%9C\"><\/span>3384: [Usaco2004 Nov]Apple Catching \u63a5\u82f9\u679c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Time Limit:\u00a01 Sec\u00a0\u00a0Memory Limit:\u00a0128 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<div>\u00a0\u00a0\u00a0\u00a0\u5f88\u5c11\u6709\u4eba\u77e5\u9053\u5976\u725b\u7231\u5403\u82f9\u679c\uff0e\u519c\u592b\u7ea6\u7ff0\u7684\u519c\u573a\u4e0a\u6709\u4e24\u68f5\u82f9\u679c\u6811\uff08\u7f16\u53f7\u4e3a1\u548c2\uff09\uff0c\u6bcf\u4e00\u68f5\u6811\u4e0a\u90fd\u957f\u6ee1\u4e86\u82f9\u679c\uff0e\u5976\u725b\u8d1d\u831c\u65e0\u6cd5\u6458\u4e0b\u6811\u4e0a\u7684\u82f9\u679c\uff0c\u6240\u4ee5\u5979\u53ea\u80fd\u7b49\u5f85\u82f9\u679c\u4ece\u6811\u4e0a\u843d\u4e0b\uff0e\u4f46\u662f\uff0c\u7531\u4e8e\u82f9\u679c\u6389\u5230\u5730\u4e0a\u4f1a\u6454\u70c2\uff0c\u8d1d\u831c\u5fc5\u987b\u5728\u534a\u7a7a\u4e2d\u63a5\u4f4f\u82f9\u679c\uff08\u6ca1\u6709\u4eba\u7231\u5403\u6454\u70c2\u7684\u82f9\u679c\uff09\uff0e\u8d1d\u831c\u5403\u4e1c\u897f\u5f88\u5feb\uff0c\u6240\u4ee5\u5979\u63a5\u5230\u82f9\u679c\u540e\u4ec5\u7528\u51e0\u79d2\u949f\u5c31\u80fd\u5403\u5b8c\uff0e\u6bcf\u4e00\u5206\u949f\uff0c\u4e24\u68f5\u82f9\u679c\u6811\u5176\u4e2d\u7684\u4e00\u68f5\u4f1a\u6389\u843d\u4e00\u4e2a\u82f9\u679c\uff0e\u8d1d\u831c\u5df2\u7ecf\u8fc7\u4e86\u8db3\u591f\u7684\u8bad\u7ec3\uff0c\u53ea\u8981\u7ad9\u5728\u6811\u4e0b\u5c31\u4e00\u5b9a\u80fd\u63a5\u4f4f\u8fd9\u68f5\u6811\u4e0a\u6389\u843d\u7684\u82f9\u679c\uff0e\u540c\u65f6\uff0c\u8d1d\u831c\u80fd\u591f\u5728\u4e24\u68f5\u6811\u4e4b\u95f4\u5feb\u901f\u79fb\u52a8\uff08\u79fb\u52a8\u65f6\u95f4\u8fdc\u5c11\u4e8e1\u5206\u949f\uff09\uff0c\u56e0\u6b64\u5f53\u82f9\u679c\u6389\u843d\u65f6\uff0c\u5979\u5fc5\u5b9a\u7ad9\u5728\u4e24\u68f5\u6811\u5176\u4e2d\u7684\u4e00\u68f5\u4e0b\u9762\uff0e\u6b64\u5916\uff0c\u5976\u725b\u4e0d\u613f\u610f\u4e0d\u505c\u5730\u5f80\u8fd4\u4e8e\u4e24\u68f5\u6811\u4e4b\u95f4\uff0c\u56e0\u6b64\u4f1a\u9519\u8fc7\u4e00\u4e9b\u82f9\u679c,\u00a0\u82f9\u679c\u6bcf\u5206\u949f\u6389\u843d\u4e00\u4e2a\uff0c\u5171T(1\u2264T\u22641000)\u5206\u949f\uff0c\u8d1d\u831c\u6700\u591a\u613f\u610f\u79fb\u52a8W(I\u2264w\u226430)\u6b21\uff0e\u73b0\u7ed9<\/div>\n<div>\u51fa\u6bcf\u5206\u949f\u6389\u843d\u82f9\u679c\u7684\u6811\u7684\u7f16\u53f7\uff0c\u8981\u6c42\u5224\u5b9a\u8d1d\u831c\u80fd\u591f\u63a5\u4f4f\u7684\u6700\u591a\u82f9\u679c\u6570\uff0e\u5f00\u59cb\u65f6\u8d1d\u831c\u57281\u53f7\u6811\u4e0b\uff0e<\/div>\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<div>\u00a0\u00a0\u00a0\u00a0\u7b2c1\u884c\uff1a\u7531\u7a7a\u683c\u9694\u5f00\u7684\u4e24\u4e2a\u6574\u6570T\u548cW.<\/div>\n<div>\u00a0\u00a0\u00a0\u00a0\u7b2c2\u5230T+1\u884c\uff1a1\u62162\uff08\u6bcf\u5206\u949f\u6389\u843d\u82f9\u679c\u7684\u6811\u7684\u7f16\u53f7\uff09\uff0e<\/div>\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<div><\/div>\n<div>\u00a0\u00a0\u00a0\u00a0\u5728\u8d1d\u831c\u79fb\u52a8\u6b21\u6570\u4e0d\u8d85\u8fc7W\u7684\u524d\u63d0\u4e0b\u5979\u80fd\u63a5\u5230\u7684\u6700\u591a\u82f9\u679c\u6570<\/div>\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\">7 2<br \/>\n2<br \/>\n1<br \/>\n1<br \/>\n2<br \/>\n2<br \/>\n1<br \/>\n1<\/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\">6<\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>&nbsp;<\/p>\n<p>7\u5206\u949f\u5185\u5171\u6389\u843d7\u4e2a\u82f9\u679c\u4e00\u4e00\u7b2c1\u4e2a\u4ece\u7b2c2\u68f5\u6811\u4e0a\u6389\u843d\uff0c\u63a5\u4e0b\u6765\u76842\u4e2a\u82f9\u679c\u4ece\u7b2c1\u68f5\u6811\u4e0a\u6389\u843d\uff0c\u518d\u63a5\u4e0b\u6765\u76842\u4e2a\u4ece\u7b2c2\u68f5\u6811\u4e0a\u6389\u843d\uff0c\u6700\u540e2\u4e2a\u4ece\u7b2c1\u68f5\u6811\u4e0a\u6389\u843d\uff0e\u00a0\u00a0\u00a0\u8d1d\u831c\u4e0d\u79fb\u52a8\u76f4\u5230\u63a5\u5230\u4ece\u7b2c1\u68f5\u6811\u4e0a\u6389\u843d\u7684\u4e24\u4e2a\u82f9\u679c\uff0c\u7136\u540e\u79fb\u52a8\u5230\u7b2c2\u68f5\u6811\u4e0b\uff0c\u76f4\u5230\u63a5\u5230\u4ece\u7b2c2\u68f5<\/p>\n<p>\u6811\u4e0a\u6389\u843d\u7684\u4e24\u4e2a\u82f9\u679c\uff0c\u6700\u540e\u79fb\u52a8\u5230\u7b2c1\u68f5\u6811\u4e0b\uff0c\u63a5\u4f4f\u6700\u540e\u4e24\u4e2a\u4ece\u7b2c1\u68f5\u6811\u4e0a\u6389\u843d\u7684\u82f9\u679c\uff0e\u8fd9\u6837\u8d1d\u831c\u5171\u63a5\u4f4f6\u4e2a\u82f9\u679c\uff0e<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u53cc\u500d\u7ecf\u9a8c\u9898\u3002\u3002\u3002 &#8211;&gt;1750<\/p>\n<p>dp<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;cstdio&gt;\r\nint max(int a,int b){return a&gt;b?a:b;}\r\nint t,w,dp[1010][33][2],n[1010],ans;\r\nint main()\r\n{\r\n    scanf(\"%d%d\",&amp;t,&amp;w);\r\n    for(int i=1;i&lt;=t;i++) scanf(\"%d\",&amp;n[i]);\r\n    for(int i=1;i&lt;=t;i++)\r\n    {\r\n        dp[i][0][0]=dp[i-1][0][0]+(n[i]==1);\r\n        dp[i][0][1]=dp[i-1][0][1]+(n[i]==2);\r\n        for(int j=1;j&lt;=w;j++)\r\n        {\r\n            dp[i][j][0]=max(dp[i-1][j-1][1],dp[i-1][j][0])+(n[i]==1);\r\n            dp[i][j][1]=max(dp[i-1][j-1][0],dp[i-1][j][1])+(n[i]==2);\r\n            ans=max(ans,max(dp[i][j][0],dp[i][j][1]));\r\n        }\r\n    }\r\n    printf(\"%d\",ans);\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 3384: [Usaco2004 Nov]Apple Catching \u63a5\u82f9\u679c Time Lim [&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],"class_list":["post-226","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\/226","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=226"}],"version-history":[{"count":3,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/226\/revisions"}],"predecessor-version":[{"id":249,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/226\/revisions\/249"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}