{"id":528,"date":"2018-03-26T13:36:08","date_gmt":"2018-03-26T05:36:08","guid":{"rendered":"http:\/\/kylelv.com\/?p=528"},"modified":"2018-05-23T13:40:02","modified_gmt":"2018-05-23T05:40:02","slug":"bzoj-2331-scoi2011%e5%9c%b0%e6%9d%bf-%e6%8f%92%e5%a4%b4dp","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=528","title":{"rendered":"bzoj 2331: [SCOI2011]\u5730\u677f  &#8212; \u63d2\u5934dp"},"content":{"rendered":"<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-69fdeefe8599b\" 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-69fdeefe8599b\"  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=528\/#2331_SCOI2011%E5%9C%B0%E6%9D%BF\" title=\"2331: [SCOI2011]\u5730\u677f\">2331: [SCOI2011]\u5730\u677f<\/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=528\/#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=528\/#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=528\/#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=528\/#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=528\/#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=528\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"2331_SCOI2011%E5%9C%B0%E6%9D%BF\"><\/span>2331: [SCOI2011]\u5730\u677f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\">Time Limit:\u00a05 Sec\u00a0\u00a0Memory Limit:\u00a0128 MB<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>lxhgww\u7684\u5c0f\u540d\u53eb\u201c\u5c0fL\u201d\uff0c\u8fd9\u662f\u56e0\u4e3a\u4ed6\u603b\u662f\u5f88\u559c\u6b22L\u578b\u7684\u4e1c\u897f\u3002\u5c0fL\u5bb6\u7684\u5ba2\u5385\u662f\u4e00\u4e2a\u7684\u77e9\u5f62\uff0c\u73b0\u5728\u4ed6\u60f3\u7528L\u578b\u7684\u5730\u677f\u6765\u94fa\u6ee1\u6574\u4e2a\u5ba2\u5385\uff0c\u5ba2\u5385\u91cc\u6709\u4e9b\u4f4d\u7f6e\u6709\u67f1\u5b50\uff0c\u4e0d\u80fd\u94fa\u5730\u677f\u3002\u73b0\u5728\u5c0fL\u60f3\u77e5\u9053\uff0c\u7528L\u578b\u7684\u5730\u677f\u94fa\u6ee1\u6574\u4e2a\u5ba2\u5385\u6709\u591a\u5c11\u79cd\u4e0d\u540c\u7684\u65b9\u6848\uff1f<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff0cL\u578b\u5730\u677f\u7684\u4e24\u7aef\u957f\u5ea6\u53ef\u4ee5\u4efb\u610f\u53d8\u5316\uff0c\u4f46\u4e0d\u80fd\u957f\u5ea6\u4e3a0\u3002\u94fa\u8bbe\u5b8c\u6210\u540e\uff0c\u5ba2\u5385\u91cc\u9762\u6240\u6709\u6ca1\u6709\u67f1\u5b50\u7684\u5730\u65b9\u90fd\u5fc5\u987b\u94fa\u4e0a\u5730\u677f\uff0c\u4f46\u540c\u4e00\u4e2a\u5730\u65b9\u4e0d\u80fd\u88ab\u94fa\u591a\u6b21\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-529\" src=\"http:\/\/kylelv.com\/wp-content\/uploads\/2018\/05\/22.gif\" alt=\"\" width=\"510\" height=\"212\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u8f93\u5165\u7684\u7b2c\u4e00\u884c\u5305\u542b\u4e24\u4e2a\u6574\u6570\uff0cR\u548cC\uff0c\u8868\u793a\u5ba2\u5385\u7684\u5927\u5c0f\u3002<\/p>\n<p>\u63a5\u7740\u662fR\u884c\uff0c\u6bcf\u884cC\u4e2a\u5b57\u7b26\u3002\u2019_\u2019\u8868\u793a\u5bf9\u5e94\u7684\u4f4d\u7f6e\u662f\u7a7a\u7684\uff0c\u5fc5\u987b\u94fa\u5730\u677f\uff1b\u2019*\u2019\u8868\u793a\u5bf9\u5e94\u7684\u4f4d\u7f6e\u6709\u67f1\u5b50\uff0c\u4e0d\u80fd\u94fa\u5730\u677f\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u8f93\u51fa\u4e00\u884c\uff0c\u5305\u542b\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u94fa\u6ee1\u6574\u4e2a\u5ba2\u5385\u7684\u65b9\u6848\u6570\u3002\u7531\u4e8e\u8fd9\u4e2a\u6570\u53ef\u80fd\u5f88\u5927\uff0c\u53ea\u9700\u8f93\u51fa\u5b83\u9664\u4ee520110520\u7684\u4f59\u6570\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"font-weight: 400;\">2 2<\/p>\n<p>*_<\/p>\n<p>__<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"font-weight: 400;\">1<\/p>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>R*C&lt;=100<\/p>\n<p>\u5165\u95e8\u7b2c\u4e00\u9898\u3002\u3002<\/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;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 inf 1000000007\r\n#define ll long long\r\n#define P 20110520\r\n#define M 200010\r\n#define N 110\r\nint n,m,ed,ans;\r\nbool mp[N][N];\r\nchar s[N];\r\nint f[2][M],v[2][M],a[N];\r\nstruct qaz{int x,z;};\r\nqueue&lt;qaz&gt;q;\r\ninline int gx(int x,int a1,int a2)\r\n{\r\n\tint sum=0;\r\n\tfor(int i=m+1;i;i--)\r\n\t\tsum=sum*3+(i==x?a1:(i==x+1?a2:a[i]));\r\n\treturn sum;\r\n}\r\nvoid up(int x,int z,int ta)\r\n{\r\n\tif(x==ed)\r\n\t{\r\n\t\t(ans+=ta)%=P;\r\n\t\treturn;\r\n\t}\r\n\tx++;\r\n\tint k=x&amp;1;\r\n\tif(v[k][z]^x)\r\n\t{\r\n\t\tv[k][z]=x;f[k][z]=0;\r\n\t\tq.push((qaz){x,z});\r\n\t}\r\n\t(f[k][z]+=ta)%=P;\r\n}\r\nint main()\r\n{\r\n\tscanf(\"%d%d\",&amp;n,&amp;m);\r\n\tfor(int i=1;i&lt;=n;i++)\r\n\t{\r\n\t\tscanf(\"%s\",s+1);\r\n\t\tfor(int j=1;j&lt;=m;j++)\r\n\t\t\tif(n&gt;m) mp[j][i]=(s[j]=='_');\r\n\t\t\telse mp[i][j]=(s[j]=='_');\r\n\t}\r\n\tif(n&lt;m) swap(n,m);\r\n\ted=n*m-1;\r\n\twhile(!mp[ed%m+1][ed\/m+1]) ed--;\r\n\tf[0][0]=v[0][0]=1;\r\n\tq.push((qaz){0,0});\r\n\tqaz p;\r\n\tint x,y,ta;\r\n\twhile(!q.empty())\r\n\t{\r\n\t\tp=q.front();q.pop();\r\n\t\tta=f[p.x&amp;1][p.z];\r\n\t\tif(p.x%m==0) p.z*=3;\r\n\t\tx=p.x%m+1;y=p.x\/m+1;\r\n\t\tmemset(a,0,m+2&lt;&lt;2);\r\n\t\tfor(int i=1,j=p.z;j;i++,j\/=3) a[i]=j%3;\r\n\t\tif(!mp[x][y]) up(p.x,gx(100,0,0),ta);\r\n\t\telse if(a[x]==1&amp;&amp;a[x+1]==1) up(p.x,gx(x,0,0),ta);\r\n\t\telse if(!a[x]&amp;&amp;!a[x+1])\r\n\t\t{\r\n\t\t\tif(mp[x+1][y]) up(p.x,gx(x,0,1),ta);\r\n\t\t\tif(mp[x][y+1]) up(p.x,gx(x,1,0),ta);\r\n\t\t\tif(mp[x][y+1]&amp;&amp;mp[x+1][y]) up(p.x,gx(x,2,2),ta);\r\n\t\t}\r\n\t\telse if(!a[x])\r\n\t\t{\r\n\t\t\tif(mp[x][y+1]) up(p.x,gx(x,a[x+1],0),ta);\r\n\t\t\tif(mp[x+1][y]&amp;&amp;a[x+1]==1) up(p.x,gx(x,0,2),ta);\r\n\t\t\tif(a[x+1]==2) up(p.x,gx(x,0,0),ta);\r\n\t\t}\r\n\t\telse if(!a[x+1])\r\n\t\t{\r\n\t\t\tif(mp[x+1][y]) up(p.x,gx(x,0,a[x]),ta);\r\n\t\t\tif(mp[x][y+1]&amp;&amp;a[x]==1) up(p.x,gx(x,2,0),ta);\r\n\t\t\tif(a[x]==2) up(p.x,gx(x,0,0),ta);\r\n\t\t}\r\n\t}\r\n\tprintf(\"%d\\n\",ans);\r\n\treturn 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2331: [SCOI2011]\u5730\u677f Time Limit:\u00a05 Sec\u00a0\u00a0Memory Limit:\u00a0128 [&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":[57,19],"class_list":["post-528","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-dp","tag-19"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/528","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=528"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/528\/revisions"}],"predecessor-version":[{"id":530,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/528\/revisions\/530"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}