{"id":518,"date":"2017-04-28T08:40:26","date_gmt":"2017-04-28T00:40:26","guid":{"rendered":"http:\/\/kylelv.com\/?p=518"},"modified":"2018-01-18T17:14:27","modified_gmt":"2018-01-18T09:14:27","slug":"bzoj-1613-usaco2007-janrunning%e8%b4%9d%e8%8c%9c%e7%9a%84%e6%99%a8%e7%bb%83%e8%ae%a1%e5%88%92-dp","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=518","title":{"rendered":"bzoj 1613: [Usaco2007 Jan]Running\u8d1d\u831c\u7684\u6668\u7ec3\u8ba1\u5212  &#8212; dp"},"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-69fdefb24b524\" 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-69fdefb24b524\"  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=518\/#1613_Usaco2007_JanRunning%E8%B4%9D%E8%8C%9C%E7%9A%84%E6%99%A8%E7%BB%83%E8%AE%A1%E5%88%92\" title=\"1613: [Usaco2007 Jan]Running\u8d1d\u831c\u7684\u6668\u7ec3\u8ba1\u5212\">1613: [Usaco2007 Jan]Running\u8d1d\u831c\u7684\u6668\u7ec3\u8ba1\u5212<\/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=518\/#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=518\/#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=518\/#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=518\/#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=518\/#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=518\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"1613_Usaco2007_JanRunning%E8%B4%9D%E8%8C%9C%E7%9A%84%E6%99%A8%E7%BB%83%E8%AE%A1%E5%88%92\"><\/span>1613: [Usaco2007 Jan]Running\u8d1d\u831c\u7684\u6668\u7ec3\u8ba1\u5212<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a05 Sec\u00a0\u00a0Memory Limit:\u00a064 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>\u5976\u725b\u4eec\u6253\u7b97\u901a\u8fc7\u953b\u70bc\u6765\u57f9\u517b\u81ea\u5df1\u7684\u8fd0\u52a8\u7ec6\u80de\uff0c\u4f5c\u4e3a\u5176\u4e2d\u7684\u4e00\u5458\uff0c\u8d1d\u831c\u9009\u62e9\u7684\u8fd0\u52a8\u65b9\u5f0f\u662f\u6bcf\u5929\u8fdb\u884cN(1 &lt;= N &lt;= 10,000)\u5206\u949f\u7684\u6668\u8dd1\u3002\u5728\u6bcf\u5206\u949f\u7684\u5f00\u59cb\uff0c\u8d1d\u831c\u4f1a\u9009\u62e9\u4e0b\u4e00\u5206\u949f\u662f\u7528\u6765\u8dd1\u6b65\u8fd8\u662f\u4f11\u606f\u3002 \u8d1d\u831c\u7684\u4f53\u529b\u9650\u5236\u4e86\u5979\u8dd1\u6b65\u7684\u8ddd\u79bb\u3002\u66f4\u5177\u4f53\u5730\uff0c\u5982\u679c\u8d1d\u831c\u9009\u62e9\u5728\u7b2ci\u5206\u949f\u5185\u8dd1\u6b65\uff0c\u5979\u53ef\u4ee5\u5728\u8fd9\u4e00\u5206\u949f\u5185\u8dd1D_i(1 &lt;= D_i &lt;= 1,000)\u7c73\uff0c\u5e76\u4e14\u5979\u7684\u75b2\u52b3\u5ea6\u4f1a\u589e\u52a0 1\u3002\u4e0d\u8fc7\uff0c\u65e0\u8bba\u4f55\u65f6\u8d1d\u831c\u7684\u75b2\u52b3\u5ea6\u90fd\u4e0d\u80fd\u8d85\u8fc7M(1 &lt;= M &lt;= 500)\u3002\u5982\u679c\u8d1d\u831c\u9009\u62e9\u4f11\u606f\uff0c\u90a3\u4e48\u5979\u7684\u75b2\u52b3\u5ea6\u5c31\u4f1a\u6bcf\u5206\u949f\u51cf\u5c111\uff0c\u4f46\u5979\u5fc5\u987b\u4f11\u606f\u5230\u75b2\u52b3\u5ea6\u6062\u590d\u52300\u4e3a\u6b62\u3002\u5728\u75b2\u52b3\u5ea6\u4e3a0\u65f6\u4f11\u606f\u7684\u8bdd\uff0c\u75b2\u52b3\u5ea6\u4e0d\u4f1a\u518d\u53d8\u52a8\u3002\u6668\u8dd1\u5f00\u59cb\u65f6\uff0c\u8d1d\u831c\u7684\u75b2\u52b3\u5ea6\u4e3a0\u3002 \u8fd8\u6709\uff0c\u5728N\u5206\u949f\u7684\u953b\u70bc\u7ed3\u675f\u65f6\uff0c\u8d1d\u831c\u7684\u75b2\u52b3\u5ea6\u4e5f\u5fc5\u987b\u6062\u590d\u52300\uff0c\u5426\u5219\u5979\u5c06\u6ca1\u6709\u8db3\u591f\u7684\u7cbe\u529b\u6765\u5bf9\u4ed8\u8fd9\u4e00\u6574\u5929\u4e2d\u5269\u4e0b\u7684\u4e8b\u60c5\u3002 \u8bf7\u4f60\u8ba1\u7b97\u4e00\u4e0b\uff0c\u8d1d\u831c\u6700\u591a\u80fd\u8dd1\u591a\u5c11\u7c73\u3002<\/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>* \u7b2c1\u884c: 2\u4e2a\u7528\u7a7a\u683c\u9694\u5f00\u7684\u6574\u6570\uff1aN \u548c M<\/p>\n<p>* \u7b2c2..N+1\u884c: \u7b2ci+1\u4e3a1\u4e2a\u6574\u6570\uff1aD_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>* \u7b2c1\u884c: \u8f93\u51fa1\u4e2a\u6574\u6570\uff0c\u8868\u793a\u5728\u6ee1\u8db3\u6240\u6709\u9650\u5236\u6761\u4ef6\u7684\u60c5\u51b5\u4e0b\uff0c\u8d1d\u831c\u80fd\u8dd1\u7684\u6700\u5927 \u8ddd\u79bb<\/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\"><span class=\"sampledata\">5 2<br \/>\n5<br \/>\n3<br \/>\n4<br \/>\n2<br \/>\n10<\/span><\/span>&nbsp;<\/p>\n<\/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\">9<\/span><\/p>\n<p>\u8f93\u51fa\u8bf4\u660e:<\/p>\n<p>\u8d1d\u831c\u5728\u7b2c1\u5206\u949f\u5185\u9009\u62e9\u8dd1\u6b65\uff08\u8dd1\u4e865\u7c73\uff09\uff0c\u5728\u7b2c2\u5206\u949f\u5185\u4f11\u606f\uff0c\u5728\u7b2c3\u5206\u949f\u5185\u8dd1<br \/>\n\u6b65\uff08\u8dd1\u4e864\u7c73\uff09\uff0c\u5269\u4f59\u7684\u65f6\u95f4\u90fd\u7528\u6765\u4f11\u606f\u3002\u56e0\u4e3a\u5728\u6668\u8dd1\u7ed3\u675f\u65f6\u8d1d\u831c\u7684\u75b2\u52b3\u5ea6\u5fc5\u987b<br \/>\n\u4e3a0\uff0c\u6240\u4ee5\u5979\u4e0d\u80fd\u5728\u7b2c5\u5206\u949f\u5185\u9009\u62e9\u8dd1\u6b65\u3002<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\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 ll long long\r\n#define N 10010\r\ninline int rd()\r\n{\r\n    int x=0,f=1;char ch=getchar();\r\n    while(ch&lt;'0'||ch&gt;'9'){if(ch=='-')f=-1;ch=getchar();}\r\n    while(ch&gt;='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\r\n    return x*f;\r\n}\r\nint f[N][520],d[N],n,m; \r\nint main()\r\n{\r\n    n=rd();m=rd();\r\n    for(int i=1;i&lt;=n;i++) d[i]=rd();\r\n    for(int i=1;i&lt;=n;i++)\r\n    {\r\n        for(int j=1;j&lt;=m;j++)\r\n        {\r\n            f[i][j]=f[i-1][j-1]+d[i];\r\n            if(i+j&lt;=n) f[i+j][0]=max(f[i+j][0],f[i][j]); \r\n        }\r\n        f[i][0]=max(f[i-1][0],f[i][0]);\r\n    }\r\n    printf(\"%d\\n\",f[n][0]);\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1613: [Usaco2007 Jan]Running\u8d1d\u831c\u7684\u6668\u7ec3\u8ba1\u5212 Time Limit:\u00a0 [&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-518","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\/518","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=518"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/518\/revisions"}],"predecessor-version":[{"id":520,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/518\/revisions\/520"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}