{"id":826,"date":"2013-09-13T18:36:49","date_gmt":"2013-09-13T10:36:49","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=826"},"modified":"2013-09-13T18:39:36","modified_gmt":"2013-09-13T10:39:36","slug":"hdu-3919-little-sheep","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/hdu-3919-little-sheep\/","title":{"rendered":"HDU 3919. Little Sheep"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>&#8230;. \u7565\uff09<br \/>\n<!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>\u3002\u3002\u9996\u5148\u9898\u76ee\u4e2d\u7684\u56fe\u6709\u4e00\u5b9a\u8bef\u5bfc\u6027\u3002\u3002\u5728\u4e2d\u95f4\u7684\u4efb\u4f55\u65f6\u523b\u3002\u3002\u5f53\u524d\u4f4d\u7f6e\u6253\u5f00\u7f8a\u5708\u6709\u4e24\u8fb9\u7684\u7f8a\u53ef\u4ee5\u8dd1\u51fa\u65f6\u3002\u3002\u90fd\u7acb\u5373\u6253\u5f00\u5f53\u524d\u4f4d\u7f6e\u7684\u7f8a\u5708\u3002\u3002\u800c\u4e0d\u4f1a\u51fa\u73b0\u56fe\u4e2d\u90a3\u79cd\u8df3\u8dc3\u7684\u60c5\u51b5\u3002\u3002\u3002\u6ce8\u610f\u5230\u521d\u59cb\u4f4d\u7f6e\u56fa\u5b9a\u3002\u3002\u3002<br \/>\n\u6240\u4ee5\u72b6\u6001\u662f\u3002\u3002<code>dp[l][r][2]<\/code> \u8868\u793a\u5411\u5de6\u8d70\u4e86 <code>l<\/code> \u6b65\u3002\u3002\u5411\u53f3\u8d70\u4e86 <code>r<\/code> \u6b65\u3002\u3002\u4e14\u5f53\u524d\u5728\u533a\u95f4 \u5de6\/\u53f3 \u7aef\u70b9\u5904\u65f6\u7684\u6700\u4f18\u503c\u3002\u3002\u3002<br \/>\n\u3002\u3002\u72b6\u6001\u7c7b\u4f3c \u9752\u86d9\u7684\u70e6\u607c\u3002\uff08\u53c2\u89c1\u9ed1\u4e66 p133\u3002<\/p>\n<p>\u3002\u3002\u8f6c\u79fb\u7684\u65f6\u5019\u9700\u8981\u4e2d\u95f4\u672a\u88ab\u8bbf\u95ee\u7684\u90e8\u5206\u7684\u4e00\u6bb5 <code>rmq<\/code>\u3002\u3002\u3002\u56e0\u4e3a\u662f\u9759\u6001\u3002\u3002\u6240\u4ee5\u9009\u62e9\u79bb\u7ebf <code>ST<\/code>\u3002\u3002\u53bb\u6389\u591a\u4f59\u90e8\u5206\u3002\u3002\u5e76\u505a\u4e00\u4e9b\u4f4d\u79fb\u3002\u3002\u53ef\u4ee5\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u907f\u514d\u72b6\u6001\u8f6c\u79fb\u7684\u65f6\u5019\u4e0d\u5c0f\u5fc3\u5199\u75b5\u3002\u3002\u3001\u3001<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = 2009, LN = 14;\r\n\r\nint ST&#x5B;LN]&#x5B;N], dp&#x5B;N]&#x5B;N]&#x5B;2];\r\nint A&#x5B;N], n, k, nn;\r\n\r\ninline int rmq(int l, int r){\r\n    r=nn-r; int lv = lg2(r-l);\r\n    return max(ST&#x5B;lv]&#x5B;l], ST&#x5B;lv]&#x5B;r-(1&lt;&lt;lv)]);\r\n}\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n    while (~scanf(&quot;%d%d&quot;, &amp;n, &amp;k)){\r\n\r\n        int s = 0; REP(i, n) s += RD(A&#x5B;i]); nn = n-(2*k+1); ++k;\r\n\r\n        REP(i, nn) ST&#x5B;0]&#x5B;i] = A&#x5B;k+i];\r\n\r\n        for ( int lv = 1 ; _1(lv) &lt; nn ; lv ++ ){\r\n            for ( int i = 0 ; i + _1(lv)  &lt;= nn ; i ++ )\r\n                ST&#x5B;lv]&#x5B;i] = max(ST&#x5B;lv-1]&#x5B;i], ST&#x5B;lv-1]&#x5B;i + _1(lv-1)]);\r\n        }\r\n\r\n        FLC(dp, 0x3f), dp&#x5B;0]&#x5B;0]&#x5B;0] = dp&#x5B;0]&#x5B;0]&#x5B;1] = 0;\r\n\r\n        FOR_1(len, 1, nn) FOR_1(l, 0, len){\r\n            int r = len - l;\r\n            if (l) dp&#x5B;l]&#x5B;r]&#x5B;0] = min(dp&#x5B;l-1]&#x5B;r]&#x5B;0] + rmq(l-1, r), dp&#x5B;l-1]&#x5B;r]&#x5B;1] + len * rmq(l-1, r));\r\n            if (r) dp&#x5B;l]&#x5B;r]&#x5B;1] = min(dp&#x5B;l]&#x5B;r-1]&#x5B;1] + rmq(l, r-1), dp&#x5B;l]&#x5B;r-1]&#x5B;0] + len * rmq(l, r-1));\r\n        }\r\n\r\n        int f = INF; FOR_1(l, 0, nn){\r\n            int r = nn - l;\r\n            REP(t, 2) checkMin(f, dp&#x5B;l]&#x5B;r]&#x5B;t]);\r\n        }\r\n\r\n        OT(s + f);\r\n    }\r\n}\r\n<\/pre>\n<p><a href=\"http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=1555178\">http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=1555178<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: &#8230;. \u7565\uff09<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[47],"tags":[],"class_list":["post-826","post","type-post","status-publish","format-standard","hentry","category-hdu"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-dk","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=826"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/826\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}