{"id":433,"date":"2017-04-12T07:52:36","date_gmt":"2017-04-11T23:52:36","guid":{"rendered":"http:\/\/kylelv.com\/?p=433"},"modified":"2018-01-03T18:14:11","modified_gmt":"2018-01-03T10:14:11","slug":"bzoj-3437-%e5%b0%8fp%e7%9a%84%e7%89%a7%e5%9c%ba-%e6%96%9c%e7%8e%87%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=433","title":{"rendered":"bzoj 3437: \u5c0fP\u7684\u7267\u573a  &#8212; \u659c\u7387\u4f18\u5316"},"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-69fdeefe2d1d0\" 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-69fdeefe2d1d0\"  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=433\/#3437_%E5%B0%8FP%E7%9A%84%E7%89%A7%E5%9C%BA\" title=\"3437: \u5c0fP\u7684\u7267\u573a\">3437: \u5c0fP\u7684\u7267\u573a<\/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=433\/#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=433\/#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=433\/#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=433\/#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=433\/#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=433\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"3437_%E5%B0%8FP%E7%9A%84%E7%89%A7%E5%9C%BA\"><\/span>3437: \u5c0fP\u7684\u7267\u573a<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a010 Sec\u00a0\u00a0Memory Limit:\u00a0128 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>\u5c0fP\u5728MC\u91cc\u6709n\u4e2a\u7267\u573a\uff0c\u81ea\u897f\u5411\u4e1c\u5448\u4e00\u5b57\u5f62\u6392\u5217\uff08\u81ea\u897f\u5411\u4e1c\u75281\u2026n\u7f16\u53f7\uff09\uff0c\u4e8e\u662f\u4ed6\u5c31\u70e6\u607c\u4e86\uff1a\u4e3a\u4e86\u63a7\u5236\u8fd9n\u4e2a\u7267\u573a\uff0c\u4ed6\u9700\u8981\u5728\u67d0\u4e9b\u7267\u573a\u4e0a\u9762\u5efa\u7acb\u63a7\u5236\u7ad9\uff0c\u6bcf\u4e2a\u7267\u573a\u4e0a\u53ea\u80fd\u5efa\u7acb\u4e00\u4e2a\u63a7\u5236\u7ad9\uff0c\u6bcf\u4e2a\u63a7\u5236\u7ad9\u63a7\u5236\u7684\u7267\u573a\u662f\u5b83\u6240\u5728\u7684\u7267\u573a\u4e00\u76f4\u5230\u5b83\u897f\u8fb9\u7b2c\u4e00\u4e2a\u63a7\u5236\u7ad9\u7684\u6240\u6709\u7267\u573a\uff08\u5b83\u897f\u8fb9\u7b2c\u4e00\u4e2a\u63a7\u5236\u7ad9\u6240\u5728\u7684\u7267\u573a\u4e0d\u88ab\u63a7\u5236\uff09\uff08\u5982\u679c\u5b83\u897f\u8fb9\u4e0d\u5b58\u5728\u63a7\u5236\u7ad9\uff0c\u90a3\u4e48\u5b83\u63a7\u5236\u897f\u8fb9\u6240\u6709\u7684\u7267\u573a\uff09\uff0c\u6bcf\u4e2a\u7267\u573a\u88ab\u63a7\u5236\u90fd\u9700\u8981\u4e00\u5b9a\u7684\u82b1\u8d39\uff08\u6bd5\u7adf\u5728\u63a7\u5236\u7ad9\u5230\u7267\u573a\u95f4\u4fee\u5efa\u9053\u8def\u662f\u9700\u8981\u8d44\u6e90\u7684\u561b~\uff09\uff0c\u800c\u4e14\u8be5\u82b1\u8d39\u7b49\u4e8e\u5b83\u5230\u63a7\u5236\u5b83\u7684\u63a7\u5236\u7ad9\u4e4b\u95f4\u7684\u7267\u573a\u6570\u76ee\uff08\u4e0d\u5305\u62ec\u81ea\u8eab\uff0c\u4f46\u5305\u62ec\u63a7\u5236\u7ad9\u6240\u5728\u7267\u573a\uff09\u4e58\u4e0a\u8be5\u7267\u573a\u7684\u653e\u517b\u91cf\uff0c\u5728\u7b2ci\u4e2a\u7267\u573a\u5efa\u7acb\u63a7\u5236\u7ad9\u7684\u82b1\u8d39\u662fai\uff0c\u6bcf\u4e2a\u7267\u573ai\u7684\u653e\u517b\u91cf\u662fbi\uff0c\u7406\u6240\u5f53\u7136\uff0c\u5c0fP\u9700\u8981\u603b\u82b1\u8d39\u6700\u5c0f\uff0c\u4f46\u662f\u5c0fP\u7684\u667a\u5546\u6709\u70b9\u4e0d\u591f\u7528\u4e86\uff0c\u6240\u4ee5\u8fd9\u4e2a\u6700\u5c0f\u603b\u82b1\u8d39\u5c31\u7531\u4f60\u6765\u7b97\u51fa\u5566\u3002<\/p>\n<p>&nbsp;<\/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\u6574\u6570 n \u8868\u793a\u7267\u573a\u6570\u76ee<\/p>\n<p>\u7b2c\u4e8c\u884c\u5305\u62ecn\u4e2a\u6574\u6570\uff0c\u7b2ci\u4e2a\u6574\u6570\u8868\u793aai<\/p>\n<p>\u7b2c\u4e09\u884c\u5305\u62ecn\u4e2a\u6574\u6570\uff0c\u7b2ci\u4e2a\u6574\u6570\u8868\u793abi<\/p>\n<p>&nbsp;<\/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>\u53ea\u6709\u4e00\u884c\uff0c\u5305\u62ec\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u6700\u5c0f\u82b1\u8d39<\/p>\n<p>&nbsp;<\/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\">4<br \/>\n2424<br \/>\n3142<\/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\"><span class=\"sampledata\"><span class=\"sampledata\">9<br \/>\n\u6837\u4f8b\u89e3\u91ca<br \/>\n\u9009\u53d6\u7267\u573a1\uff0c3\uff0c4\u5efa\u7acb\u63a7\u5236\u7ad9\uff0c\u6700\u5c0f\u8d39\u7528\u4e3a2+(2+1*1)+4=9\u3002<br \/>\n1&lt;=n&lt;=1000000, 0 &lt; a i ,bi &lt; = 10000<\/span><\/span>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u8bbe\u5b9adp[i]\u4e3a\u524d\u5728i\u5904\u653e\u63a7\u5236\u53f0\u7684\u7b54\u6848<\/p>\n<p>\u90a3\u4e48<\/p>\n<p>dp[i] = min{ dp[j] + (s[i]-s[j])*i &#8211; (c[i]-c[j]) } +a[i] \u00a0 \uff0cj&lt;i<\/p>\n<p>\u5176\u4e2d s[i] \u4e3a b[i] \u7684\u524d\u7f00\u548c, c[i] \u4e3a b[i]*i \u7684\u524d\u7f00\u548c<\/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 ll long long\r\n#define N 1000100\r\n#define db double\r\nchar xB[1&lt;&lt;15],*xS=xB,*xTT=xB;\r\n#define getc() (xS==xTT&amp;&amp;(xTT=(xS=xB)+fread(xB,1,1&lt;&lt;15,stdin),xS==xTT)?0:*xS++)\r\n#define isd(c) (c&gt;='0'&amp;&amp;c&lt;='9')\r\ninline int read(){\r\n    char xchh;\r\n    int xaa;\r\n    while(xchh=getc(),!isd(xchh));(xaa=xchh-'0');\r\n    while(xchh=getc(),isd(xchh))xaa=xaa*10+xchh-'0';return xaa;\r\n}\r\nll c[N],s[N],dp[N],n,a[N],b[N];\r\nint l,r,q[N],now;\r\ndb cal(int j,int k){return (db)(dp[j]-dp[k]+c[j]-c[k])\/(db)(s[j]-s[k]);}\r\nint main()\r\n{\r\n    n=read();\r\n    for(int i=1;i&lt;=n;i++) a[i]=read();\r\n    for(int i=1;i&lt;=n;i++) b[i]=read();\r\n    for(int i=1;i&lt;=n;i++) s[i]+=s[i-1]+b[i];\r\n    for(int i=1;i&lt;=n;i++) c[i]+=c[i-1]+b[i]*i;\r\n    for(int i=1;i&lt;=n;i++)\r\n    {\r\n        while(l&lt;r&amp;&amp;cal(q[l],q[l+1])&lt;i) l++;\r\n        now=q[l];\r\n        dp[i]=dp[now]+(s[i]-s[now])*i-(c[i]-c[now])+a[i];\r\n        while(l&lt;r&amp;&amp;cal(i,q[r])&lt;cal(q[r],q[r-1])) r--;\r\n        q[++r]=i;\r\n    }\r\n    printf(\"%lld\\n\",dp[n]);\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 3437: \u5c0fP\u7684\u7267\u573a Time Limit:\u00a010 Sec\u00a0\u00a0Memory Limit:\u00a012 [&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,45],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-dp","tag-45"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/433","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=433"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":435,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions\/435"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}