{"id":180,"date":"2011-08-16T12:24:17","date_gmt":"2011-08-16T04:24:17","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=180"},"modified":"2020-06-04T12:24:54","modified_gmt":"2020-06-04T04:24:54","slug":"ural-1119-metro","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=180","title":{"rendered":"URAL 1119 Metro"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/*\ndp\u6eda\u52a8\u6570\u7ec4\n\u7b2c\u4e00\u6b21\u7528\u6eda\u52a8\u6570\u7ec4\n\u611f\u89c9\u633a\u597d\n\u4e4b\u524d\u7528\u4e8c\u7ef4double\u578b\u6570\u7ec4\nMLE\n\u5728\u8fd0\u884c\u7ed3\u679c\u91cc\u770b\u5230\u6709\u4eba\u75284080K\u8fc7\u4e86\uff08\u9650\u52364M\uff09\n\u795e\u4eba\u4e5f\u3002\u3002\u3002\n*\/\n#define LOCAL\n#include&lt;iostream>\n#include&lt;cstdio>\n#include&lt;cmath>\n#include&lt;cstring>\n#include&lt;cstdlib>\n#include&lt;iomanip>\n#include&lt;string>\n#include&lt;algorithm>\n#include&lt;ctime>\n#include&lt;stack>\n#include&lt;queue>\n#include&lt;vector>\n#define N 1005\ndouble dp1&#91;N],dp2&#91;N];\nbool cross&#91;N]&#91;N];\ndouble minthree(double a,double b,double c)\n{if(a&lt;=b&amp;&amp;a&lt;=c)return a;\nelse if(b&lt;=a&amp;&amp;b&lt;=c)return b;\nelse if(c&lt;=a&amp;&amp;c&lt;=b)return c;}\ndouble mintwo(double a,double b)\n{if(a&lt;b)return a;else return b;}\nusing namespace std;\nint main()\n{\n#ifdef LOCAL\n       freopen(\"input.txt\",\"r\",stdin);\n       freopen(\"output.txt\",\"w\",stdout);\n#endif\n \n\tint n,m,ncross,i,j,x,y;\n\tdouble diag=100*sqrt((double)2);\n\tcin>>m>>n>>ncross;m++;n++;\n\tmemset(dp2,0,sizeof(dp2));\n\tmemset(cross,0,sizeof(cross));\n\tfor(i=0;i&lt;ncross;i++)\n\t{cin>>x>>y;cross&#91;x]&#91;y]=true;}\n\tdp1&#91;1]=0;\n\tfor(i=2;i&lt;=n;i++) {dp1&#91;i]=dp1&#91;i-1]+100;}\n\tfor(i=2;i&lt;=m;i++)\n\t{\n\t\tfor(j=1;j&lt;=n;j++)\n\t\t{\n\t\t\tif(j==1) {dp2&#91;j]=dp1&#91;j]+100;}\n\t\t\telse if(cross&#91;i-1]&#91;j-1]) {dp2&#91;j]=minthree(dp1&#91;j-1]+diag,dp1&#91;j]+100,dp2&#91;j-1]+100);}\n\t\t\telse {dp2&#91;j]=mintwo(dp1&#91;j]+100,dp2&#91;j-1]+100);}\n\t\t}\n\t\tmemcpy(dp1,dp2,sizeof(double)*N);\n\t\tmemset(dp2,0,sizeof(dp2));\n\t}\n\tcout&lt;&lt;(int)(dp1&#91;n]+0.5)&lt;&lt;endl;\n\treturn 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-180","post","type-post","status-publish","format-standard","hentry","category-06-01-acm"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=180"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/180\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}