{"id":321,"date":"2017-01-10T11:22:00","date_gmt":"2017-01-10T03:22:00","guid":{"rendered":"http:\/\/kylelv.com\/?p=321"},"modified":"2017-12-22T20:04:33","modified_gmt":"2017-12-22T12:04:33","slug":"bzoj-1001-beijing2006%e7%8b%bc%e6%8a%93%e5%85%94%e5%ad%90-%e6%9c%80%e5%b0%8f%e5%89%b2","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=321","title":{"rendered":"bzoj 1001: [BeiJing2006]\u72fc\u6293\u5154\u5b50  &#8212; \u6700\u5c0f\u5272"},"content":{"rendered":"<p><center><\/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-69fdeef2b5076\" 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-69fdeef2b5076\"  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=321\/#1001_BeiJing2006%E7%8B%BC%E6%8A%93%E5%85%94%E5%AD%90\" title=\"1001: [BeiJing2006]\u72fc\u6293\u5154\u5b50\">1001: [BeiJing2006]\u72fc\u6293\u5154\u5b50<\/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=321\/#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=321\/#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=321\/#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=321\/#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=321\/#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=321\/#HINT\" title=\"HINT\">HINT<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.kylelv.com\/?p=321\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"1001_BeiJing2006%E7%8B%BC%E6%8A%93%E5%85%94%E5%AD%90\"><\/span>1001: [BeiJing2006]\u72fc\u6293\u5154\u5b50<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span class=\"green\">Time Limit:\u00a015 Sec\u00a0\u00a0Memory Limit:\u00a0162 MB<\/span><\/center><\/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<div>\u73b0\u5728\u5c0f\u670b\u53cb\u4eec\u6700\u559c\u6b22\u7684&#8221;\u559c\u7f8a\u7f8a\u4e0e\u7070\u592a\u72fc&#8221;,\u8bdd\u8bf4\u7070\u592a\u72fc\u6293\u7f8a\u4e0d\u5230\uff0c\u4f46\u6293\u5154\u5b50\u8fd8\u662f\u6bd4\u8f83\u5728\u884c\u7684\uff0c<\/div>\n<div>\u800c\u4e14\u73b0\u5728\u7684\u5154\u5b50\u8fd8\u6bd4\u8f83\u7b28\uff0c\u5b83\u4eec\u53ea\u6709\u4e24\u4e2a\u7a9d\uff0c\u73b0\u5728\u4f60\u505a\u4e3a\u72fc\u738b\uff0c\u9762\u5bf9\u4e0b\u9762\u8fd9\u6837\u4e00\u4e2a\u7f51\u683c\u7684\u5730\u5f62\uff1a<\/div>\n<p><img decoding=\"async\" src=\"http:\/\/www.lydsy.com\/JudgeOnline\/images\/1001.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<div>\u5de6\u4e0a\u89d2\u70b9\u4e3a(1,1),\u53f3\u4e0b\u89d2\u70b9\u4e3a(N,M)(\u4e0a\u56fe\u4e2dN=4,M=5).\u6709\u4ee5\u4e0b\u4e09\u79cd\u7c7b\u578b\u7684\u9053\u8def<\/div>\n<div>1:(x,y)&lt;==&gt;(x+1,y)<\/div>\n<div>2:(x,y)&lt;==&gt;(x,y+1)<\/div>\n<div>3:(x,y)&lt;==&gt;(x+1,y+1)<\/div>\n<div>\u9053\u8def\u4e0a\u7684\u6743\u503c\u8868\u793a\u8fd9\u6761\u8def\u4e0a\u6700\u591a\u80fd\u591f\u901a\u8fc7\u7684\u5154\u5b50\u6570\uff0c\u9053\u8def\u662f\u65e0\u5411\u7684. \u5de6\u4e0a\u89d2\u548c\u53f3\u4e0b\u89d2\u4e3a\u5154\u5b50\u7684\u4e24\u4e2a\u7a9d\uff0c<\/div>\n<div>\u5f00\u59cb\u65f6\u6240\u6709\u7684\u5154\u5b50\u90fd\u805a\u96c6\u5728\u5de6\u4e0a\u89d2(1,1)\u7684\u7a9d\u91cc\uff0c\u73b0\u5728\u5b83\u4eec\u8981\u8dd1\u5230\u53f3\u4e0b\u89e3(N,M)\u7684\u7a9d\u4e2d\u53bb\uff0c\u72fc\u738b\u5f00\u59cb\u4f0f\u51fb<\/div>\n<div>\u8fd9\u4e9b\u5154\u5b50.\u5f53\u7136\u4e3a\u4e86\u4fdd\u9669\u8d77\u89c1\uff0c\u5982\u679c\u4e00\u6761\u9053\u8def\u4e0a\u6700\u591a\u901a\u8fc7\u7684\u5154\u5b50\u6570\u4e3aK\uff0c\u72fc\u738b\u9700\u8981\u5b89\u6392\u540c\u6837\u6570\u91cf\u7684K\u53ea\u72fc\uff0c<\/div>\n<div>\u624d\u80fd\u5b8c\u5168\u5c01\u9501\u8fd9\u6761\u9053\u8def\uff0c\u4f60\u9700\u8981\u5e2e\u52a9\u72fc\u738b\u5b89\u6392\u4e00\u4e2a\u4f0f\u51fb\u65b9\u6848\uff0c\u4f7f\u5f97\u5728\u5c06\u5154\u5b50\u4e00\u7f51\u6253\u5c3d\u7684\u524d\u63d0\u4e0b\uff0c\u53c2\u4e0e\u7684<\/div>\n<div>\u72fc\u7684\u6570\u91cf\u8981\u6700\u5c0f\u3002\u56e0\u4e3a\u72fc\u8fd8\u8981\u53bb\u627e\u559c\u7f8a\u7f8a\u9ebb\u70e6.<\/div>\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<div>\u7b2c\u4e00\u884c\u4e3aN,M.\u8868\u793a\u7f51\u683c\u7684\u5927\u5c0f\uff0cN,M\u5747\u5c0f\u4e8e\u7b49\u4e8e1000.<\/div>\n<div>\u63a5\u4e0b\u6765\u5206\u4e09\u90e8\u5206<\/div>\n<div>\u7b2c\u4e00\u90e8\u5206\u5171N\u884c\uff0c\u6bcf\u884cM-1\u4e2a\u6570\uff0c\u8868\u793a\u6a2a\u5411\u9053\u8def\u7684\u6743\u503c.<\/div>\n<div>\u7b2c\u4e8c\u90e8\u5206\u5171N-1\u884c\uff0c\u6bcf\u884cM\u4e2a\u6570\uff0c\u8868\u793a\u7eb5\u5411\u9053\u8def\u7684\u6743\u503c.<\/div>\n<div>\u7b2c\u4e09\u90e8\u5206\u5171N-1\u884c\uff0c\u6bcf\u884cM-1\u4e2a\u6570\uff0c\u8868\u793a\u659c\u5411\u9053\u8def\u7684\u6743\u503c.<\/div>\n<div>\u8f93\u5165\u6587\u4ef6\u4fdd\u8bc1\u4e0d\u8d85\u8fc710M<\/div>\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>\u8f93\u51fa\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u53c2\u4e0e\u4f0f\u51fb\u7684\u72fc\u7684\u6700\u5c0f\u6570\u91cf.<\/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\">3 4<br \/>\n5 6 4<br \/>\n4 3 1<br \/>\n7 5 3<br \/>\n5 6 7 8<br \/>\n8 7 6 5<br \/>\n5 5 5<br \/>\n6 6 6<\/span><\/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\">14<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>&nbsp;<\/p>\n<p>2015.4.16\u65b0\u52a0\u6570\u636e\u4e00\u7ec4\uff0c\u53ef\u80fd\u4f1a\u5361\u6389\u4ece\u524d\u53ef\u4ee5\u8fc7\u7684\u7a0b\u5e8f\u3002<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6700\u5927\u6d41\u6700\u5c0f\u5272\u5b9a\u7406<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;queue&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;string&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 F(i,l,r) for(int i=l;i&lt;r;i++)\r\n#define N 1000001\r\n#define inf 1e9+5\r\ninline int read()\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\nstruct ljn{int fro,to,v;}e[N*6];\r\nint cnt=1,lj[N],n,m,tt,ans=0,S,T,dis[N];\r\ninline void add(int u,int v,int p){cnt++;e[cnt].to=v;e[cnt].fro=lj[u];e[cnt].v=p;lj[u]=cnt;}\r\ninline bool bfs()\r\n{\r\n    F(i,S,T+1) dis[i]=0;\r\n    dis[S]=1;\r\n    static queue&lt;int&gt;q;\r\n    q.push(S);\r\n    while(!q.empty())\r\n    {\r\n        int tp=q.front();\r\n        q.pop();\r\n        for(int i=lj[tp];i;i=e[i].fro)\r\n        {\r\n            if(e[i].v&amp;&amp;!dis[e[i].to])\r\n            {\r\n                dis[e[i].to]=dis[tp]+1;\r\n                q.push(e[i].to);\r\n            }\r\n        }\r\n    }\r\n    return dis[T]?1:0;\r\n}\r\ninline int dfs(int x,int p)\r\n{\r\n    if(x==T||p==0) return p;\r\n    int tmp=0,tp;\r\n    for(int i=lj[x];i;i=e[i].fro)\r\n    {\r\n        if(e[i].v&amp;&amp;dis[e[i].to]==dis[x]+1)\r\n        {\r\n            tp=dfs(e[i].to,min(p-tmp,e[i].v));\r\n            e[i].v-=tp;\r\n            e[i^1].v+=tp;\r\n            tmp+=tp;\r\n            if(p==tmp) return tmp;\r\n        }\r\n    }\r\n    if(tmp==0) dis[x]=0;\r\n    return tmp;\r\n}\r\nint main()\r\n{\r\n    n=read();m=read();\r\n    S=0;T=n*m+1;\r\n    add(S,1,inf);add(1,S,inf);\r\n    add(m*n,T,inf);add(T,m*n,inf);\r\n    F(i,0,n) F(j,1,m)\r\n    {\r\n        tt=read();\r\n        add(i*m+j,i*m+j+1,tt);\r\n        add(i*m+j+1,i*m+j,tt);\r\n    }\r\n    F(i,0,n-1) F(j,1,m+1)\r\n    {\r\n        tt=read();\r\n        add(i*m+j,(i+1)*m+j,tt);\r\n        add((i+1)*m+j,i*m+j,tt);\r\n    }\r\n    F(i,0,n-1) F(j,1,m)\r\n    {\r\n        tt=read();\r\n        add(i*m+j,(i+1)*m+j+1,tt);\r\n        add((i+1)*m+j+1,i*m+j,tt);\r\n    }\r\n    while(bfs()) ans+=dfs(S,inf);\r\n    printf(\"%d\\n\",ans);\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1001: [BeiJing2006]\u72fc\u6293\u5154\u5b50 Time Limit:\u00a015 Sec\u00a0\u00a0Memory Limi [&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":[21],"class_list":["post-321","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-21"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/321","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=321"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions\/322"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}