{"id":604,"date":"2012-12-21T22:52:05","date_gmt":"2012-12-21T14:52:05","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=604"},"modified":"2012-12-21T22:54:19","modified_gmt":"2012-12-21T14:54:19","slug":"bzoj-1233-usaco2009open%e5%b9%b2%e8%8d%89%e5%a0%86tower","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/bzoj-1233-usaco2009open%e5%b9%b2%e8%8d%89%e5%a0%86tower\/","title":{"rendered":"BZOJ 1233. [Usaco2009Open]\u5e72\u8349\u5806tower"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>&#8230; \u6309\u987a\u5e8f\u6446\u653e n \u6346\u5e72\u8349\u5806 \u3002\u3002\u3002\u95ee\u6700\u9ad8\u53ef\u4ee5\u53e0\u591a\u5c11\u5c42\u3002\u3002<br \/>\n\uff08\u6bcf\u4e00\u7ea7\u4e0d\u80fd\u6bd4\u4e0b\u9762\u4e00\u7ea7\u5bbd\u3002\u3002\u3002<br \/>\n<!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>\u3002\u3002\u6709\u4e2a\u770b\u4e0a\u53bb\u201c\u663e\u7136\u201d\u7684\u8d2a\u5fc3\u3002\u3002\uff08\u4e0d\u8fc7\u662f\u9519\u8bef\u7684\u3002\u3002<br \/>\n\u3002\u6b63\u786e\u505a\u6cd5\u662f\u8bc1\u4e00\u4e2a\u7ed3\u8bba\uff08\u5728\u591a\u79cd\u53ef\u884c\u7684\u5806\u53e0\u65b9\u6848\u4e2d\uff0c\u81f3\u5c11\u6709\u4e00\u79cd\u80fd\u4f7f\u5c42\u6570\u6700\u9ad8\u7684\u65b9\u6848\u540c\u65f6\u4f7f\u5f97\u5e95\u8fb9\u6700\u77ed\u3002\uff09\u3002\u3002\u7136\u540e\u5355\u8c03\u961f\u5217 DP \u3002\u3002<\/p>\n<p>\u3002\u3002\u8fd8\u662f\u76f4\u63a5\u8d34 \u79cb\u9192\u534a\u68a6\u65f6 \u7684\u9898\u89e3\u597d\u4e86\u3002\u3002\u3002\u3002<\/p>\n<blockquote><p>\n\u6211\u6700\u5f00\u59cb\u5c31\u72af\u4e86\u4e00\u4e2a\u4e25\u91cd\u7684\u9519\u8bef\uff0c\u8bef\u4ee5\u4e3a\u8fd9\u9898\u662f\u8d2a\u5fc3\u3002\u600e\u4e48\u8d2a\u5462\uff0c\u5c31\u662f\u6700\u540e\u4e00\u5757\u4f5c\u9876\u5c42\uff0c\u7136\u540e\u6bcf\u6b21\u9009\u5230\u5927\u4e8e\u7b49\u4e8e\u4e0a\u4e00\u5c42\u5c31\u505c\u6b62\u8fd9\u4e00\u5c42\uff0c\u5f00\u59cb\u9009\u4e0b\u4e00\u5c42\u3002<br \/>\n\u4e4d\u4e00\u770b\u597d\u50cf\u662f\u6ca1\u95ee\u9898\uff0c\u53ef\u662f\u5176\u5b9e\u662f\u4e0d\u5bf9\u7684\u3002\u4ec0\u4e48\uff1f\u4f60\u4e5f\u89c9\u5f97\u662f\u5bf9\u7684\uff0c\u8bf7\u770b\u4e0b\u9762\u4e00\u7ec4\u6570\u636e\u3002<\/p>\n<pre>\r\n5 \r\n11 \r\n5 \r\n5 \r\n2 \r\n8\r\n<\/pre>\n<p>\u8fd9\u6837\u8d2a\u5fc3\u7684\u7ed3\u679c\u662f2\uff0c\u5176\u5b9e\u7b54\u6848\u5e94\u8be5\u662f3\u3002<br \/>\n\u95ee\u9898\u5c31\u6765\u4e86\uff0c\u6211\u4eec\u8fd9\u6837\u8d2a\u5fc3\u7684\u601d\u8def\u662f\u5c3d\u91cf\u7ed9\u4e0b\u9762\u7684\u591a\u7559\u5e72\u8349\u5305\uff0c\u53ef\u8fd9\u6837\u4e0d\u4e00\u5b9a\u662f\u6700\u4f18\u89e3\u3002\u90a3\u4e48\u6211\u4eec\u53cd\u8fc7\u6765\uff0c\u5c3d\u91cf\u7ed9\u4e0a\u9762\u591a\u7559\u5e72\u8349\u5305\u5462\uff1f<br \/>\n\u62bd\u8c61\u5316\u4e00\u70b9\uff0c\u4fbf\u662f\uff1a\u5728\u591a\u79cd\u53ef\u884c\u7684\u5806\u53e0\u65b9\u6848\u4e2d\uff0c\u81f3\u5c11\u6709\u4e00\u79cd\u80fd\u4f7f\u5c42\u6570\u6700\u9ad8\u7684\u65b9\u6848\u540c\u65f6\u4f7f\u5f97\u5e95\u8fb9\u6700\u77ed\u3002\u5373\u5e95\u8fb9\u6700\u77ed\u7684\uff0c\u5c42\u6570\u4e00\u5b9a\u6700\u9ad8\u3002<br \/>\n\u4e8b\u5b9e\u8bc1\u660e\uff0c\u8fd9\u6837\u662f\u6b63\u786e\u7684\u3002\u8bc1\u660e\uff1f\u5f15\u7528\u4e00\u6bb5\u5f20\u6606\u73ae\u5927\u725b\u7684\uff1a<\/p>\n<blockquote><p>\n\u201c\u4efb\u610f\u53d6\u51fa\u4e00\u4e2a\u80fd\u4f7f\u5c42\u6570\u6700\u9ad8\u7684\u65b9\u6848\uff0c\u8bbe\u6709CA\u5c42\uff0c\u628a\u5176\u4e2d\u4ece\u4e0b\u5f80\u4e0a\u6bcf\u4e00\u5c42\u6700\u5927\u7684\u5757\u7f16\u53f7\u8bb0\u4e3aAi\uff1b\u4efb\u53d6\u4e00\u4e2a\u80fd\u4f7f\u5e95\u8fb9\u6700\u77ed\u7684\u65b9\u6848\uff0c\u8bbe\u6709CB\u5c42\uff0c\u628a\u5176\u4e2d\u4ece\u4e0b\u5f80\u4e0a\u6bcf\u4e00\u5c42\u6700\u5927\u7684\u5757\u7f16\u53f7\u8bb0\u4e3aBi\u3002\u663e\u7136A1>=B1,ACB<=BCB\uff0c\u8fd9\u8bf4\u660e\u81f3\u5c11\u5b58\u5728\u4e00\u4e2ak\u5c5e\u4e8e(1,CB)\uff0c\u6ee1\u8db3Ak-1>=Bk-1\u4e14Ak<=Bk\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u65b9\u6848 A \u7b2cK \u5c42\u5b8c\u5168\u88ab\u65b9\u6848 B \u7b2cK \u5c42\u5305\u542b\u3002\u6784\u9020\u4e00\u4e2a\u65b0\u65b9\u6848\uff0c\u7b2cK \u5c42\u5f80\u4e0a\u6309\u65b9\u6848 A\uff0c\u5f80\u4e0b\u6309\u65b9\u6848 B\uff0c\u4e24\u8fb9\u90fd\u4e0d\u8981\u7684\u5757\u653e\u4e2d\u95f4\u5f53\u7b2cK \u5c42\u3002\u65b0\u65b9\u6848\u7684\u5c42\u6570\u4e0e A \u76f8\u540c\uff0c\u800c\u5e95\u8fb9\u957f\u5ea6\u4e0e B \u76f8\u540c\u3002\u8bc1\u6bd5\u3002\u201d\n<\/p><\/blockquote>\n<p>\u73b0\u5728\u7684\u95ee\u9898\u662f\uff0c\u600e\u4e48\u7ed9\u4e0a\u9762\u591a\u7559\u5e72\u8349\u5305\uff0c\u53c8\u4fdd\u8bc1\u6709\u89e3\u5462\uff1f<\/p>\n<p>\u8bbeF[i]\u4e3a\u7b2ci..N\u4e2a\u5e72\u8349\u5305\u6240\u53e0\u6210\u7684\u5854\u5e95\u5c42\u6700\u77ed\u8fb9\u7684\u503c\u3002<br \/>\ntot[i]\u4e3a1..i\u7684\u5e72\u8349\u5806\u5bbd\u5ea6\u548c\u3002<\/p>\n<p>\u663e\u7136F[i]=min(tot[j-1]-tot[i-1])  j>i \u4e14 tot[j-1]-tot[i-1]>=F[j]<br \/>\n\u4e0d\u96be\u770b\u51fa\u8fd9\u6837\u7684\u89e3\u6cd5\u662fO(n^2)\uff0c\u53ef\u8fc79\u4e2a\u70b9(\u4e00\u517115\u4e2a\u70b9)\u3002<\/p>\n<p>\u53ef\u4ee5\u7528\u5355\u8c03\u961f\u5217\u6765\u4f18\u5316\u3002<br \/>\n\u73b0\u5728\u6709j<k\uff0c\u9996\u5148\u5982\u679c\u80fd\u7528j\u7684\u65f6\u5019\uff0cj\u80af\u5b9a\u6bd4k\u4f18\u3002\u90a3\u4e48\u5982\u679c\u4e24\u4e2a\u73b0\u5728\u90fd\u4e0d\u80fd\u7528\u7684\u65f6\u5019\uff0c\u8c01\u4f18\u5462(\u4e3a\u4e86\u4fdd\u6301\u961f\u5217\u5355\u8c03\u6027)\u3002\nk\u6bd4j\u7684\u4f18\u52bf\u5c31\u5728\u4e8e\u5176\u591a\u52a0\u4e86\u4e00\u4e2atot[k-1]-tot[j-1](j..k-1\u7684\u503c)\uff0c\u8fd9\u6837\u4f7f\u5f97tot[x-1]-tot[i-1]\u624d\u53ef\u80fd>=F[x]\u3002<br \/>\n\u90a3\u4e48\u5982\u679cf[k]-(tot[k-1]-tot[j-1])\u5374\u4e0d\u80fd<=f[j]\u7684\u8bdd\uff0ck\u5c31\u6ca1\u6709\u4e86\u4e00\u70b9\u4f18\u52bf\uff0c\u5373\u4e0d\u53ef\u80fd\u5b58\u5728\u7528k\u4e0d\u7528j\u7684\u60c5\u51b5\u3002\n.. .\n<\/p><\/blockquote>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: ; toolbar: true; notranslate\" title=\"\">\u5e72\u8349\u5806tower.cpp&quot;]\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 100009;\r\nint f&#x5B;N], g&#x5B;N], s&#x5B;N], q&#x5B;N], cz, op;\r\n\/\/ f&#x5B;i] = s&#x5B;j] - s&#x5B;i], \u4ece i+1 \u4f4d\u7f6e\u5f00\u59cb\u5806\u6700\u9ad8\u65f6\u5e95\u5c42\u7684\u6700\u5c0f\u5bbd\u5ea6\u3002\r\n\/\/ g&#x5B;i] \u4ece i+1 \u4f4d\u7f6e\u5f00\u59cb\u65f6\u6700\u9ad8\u53ef\u4ee5\u5806\u591a\u5c11\u5c42\u3002\r\nint 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#endif\r\n\r\n    REP_C(i, RD(n)) s&#x5B;i+1] = s&#x5B;i] + RD();\r\n\r\n    g&#x5B;n] = 0, q&#x5B;cz = 0] = n, op = 0; DWN(i, n, 0){\r\n        while (cz &lt; op &amp;&amp; f&#x5B;q&#x5B;cz+1]] &lt;= s&#x5B;q&#x5B;cz+1]] - s&#x5B;i]) ++cz;\r\n        f&#x5B;i] = s&#x5B;q&#x5B;cz]] - s&#x5B;i], g&#x5B;i] = g&#x5B;q&#x5B;cz]] + 1;\r\n        while (cz &lt;= op &amp;&amp; f&#x5B;q&#x5B;op]] - s&#x5B;q&#x5B;op]] &gt;= f&#x5B;i] - s&#x5B;i]) --op;\r\n        q&#x5B;++op] = i;\r\n    }\r\n\r\n    OT(g&#x5B;0]);\r\n}\r\n\r\n<\/pre>\n<h3>External link: <\/h3>\n<p><a href=\"http:\/\/www.lydsy.com\/JudgeOnline\/problem.php?id=1233\">http:\/\/www.lydsy.com\/JudgeOnline\/problem.php?id=1233<\/a><br \/>\n<a href=\"http:\/\/zzlqxbms.diandian.com\/post\/2010-06-09\/16044788\">http:\/\/zzlqxbms.diandian.com\/post\/2010-06-09\/16044788<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: &#8230; \u6309\u987a\u5e8f\u6446\u653e n \u6346\u5e72\u8349\u5806 \u3002\u3002\u3002\u95ee\u6700\u9ad8\u53ef\u4ee5\u53e0\u591a\u5c11\u5c42\u3002\u3002 \uff08\u6bcf\u4e00\u7ea7\u4e0d\u80fd\u6bd4\u4e0b\u9762\u4e00\u7ea7\u5bbd\u3002\u3002\u3002<\/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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[22],"tags":[73],"class_list":["post-604","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-73"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-9K","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/604","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=604"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/604\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}