{"id":77,"date":"2011-03-19T07:53:43","date_gmt":"2011-03-18T23:53:43","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=77"},"modified":"2020-02-25T20:20:17","modified_gmt":"2020-02-25T12:20:17","slug":"poj-1038-bugs-integrated-inc","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/poj-1038-bugs-integrated-inc\/","title":{"rendered":"POJ 1038. Bugs Integrated, Inc."},"content":{"rendered":"<h3>Brief description :<\/h3>\n<p>\u7ed9\u5b9a\u4e00\u5757 n \u00d7 m \u7684\u7535\u8def\u677f\uff0c\u4e0a\u9762\u6709\u4e00\u4e9b\u4f4d\u7f6e\u662f\u574f\u7684\uff0c\u95ee\u6700\u591a\u53ef\u4ee5\u9576\u5d4c\u591a\u5c112 \u00d7 3\u5927\u5c0f\u7684\u82af\u7247\u3002<br \/>\n\uff081 &lt; = n &lt;= 150, 1 &lt;= m &lt;= 10 &#8230;\uff09<br \/>\n<!--more--><\/p>\n<h3>Analyse :<\/h3>\n<p>&#8230;<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\nconst int hh = 150, ww = 10, _W = 16, ss = 1123; \/\/1 &lt;&lt; 20; \/\/?\r\nconst int _A = (1 &lt;&lt; ww) - 1, _B = _A &lt;&lt; _W;\r\nint O&#x5B;hh+1];\r\nint h, w, s0, s1, s2, up;\r\nshort ans, b;\r\n\r\nstruct hashTable {\r\n\tint state&#x5B;ss], head&#x5B;ss], next&#x5B;ss], sz;\r\n\tshort key&#x5B;ss];\r\n\t\r\n\tinline void clear() {\r\n\t\tsz = 0;\r\n\t\tmemset(head, -1, sizeof(head));\r\n\t}\r\n\tinline void insert(int s0, int s1, short val) {\r\n\t\tint s = s0 | s1 | s1 &lt;&lt; _W;\r\n\t\tint x = s % ss;\r\n\t\tfor ( int it = head&#x5B;x] ; it != -1 ; it = next&#x5B;it] ) {\r\n\t\t\tif ( state&#x5B;it] == s ) {\r\n\t\t\t\tkey&#x5B;it] = max(key&#x5B;it], val);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t}\r\n\t\tstate&#x5B;sz] = s, key&#x5B;sz] = val;\r\n\t\tnext&#x5B;sz] = head&#x5B;x];\r\n\t\thead&#x5B;x] = sz++;\r\n\t}\r\n\tinline short search(int s){\r\n\t\tint x = s % ss;\r\n\t\tfor ( int it = head&#x5B;x] ; it != -1 ; it = next&#x5B;it])\r\n\t\t\tif ( state&#x5B;it] == s ) return key&#x5B;it];\r\n\t\treturn 0;\r\n\t}\r\n} H&#x5B;2] , *src , *des;\r\n\r\n\r\nvoid dfs(int j, short d, int s1, int s2){\r\n\twhile (true){\r\n\t\tif (j == w){\r\n\t\t\tdes-&gt;insert(s1, s2, b + d);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\telse {\r\n\t\t\tif (j &lt; w-2 &amp;&amp; !(s0 &amp; 7 &lt;&lt; j))\r\n\t\t\t\tdfs(j+3, d+1, s1 | 7 &lt;&lt; j, s2);\r\n\t\t\tif (j &lt; w-1 &amp;&amp; !(s0 &amp; 3 &lt;&lt; j) &amp;&amp; !(s2 &amp; 3 &lt;&lt; j))\r\n\t\t\t\tdfs(j+2, d+1, s1, s2 | 3 &lt;&lt; j);\r\n\t\t}\r\n\t\tj++;\r\n\t}\r\n}\r\n\r\n\r\nvoid solve(){\r\n\tsrc = H, des = src + 1, des-&gt;clear(), des-&gt;insert(O&#x5B;0], O&#x5B;1], 0);\r\n\t\r\n\tfor (int i = 0; i &lt; h - 1; i ++){\r\n\t\tswap(src, des), des-&gt;clear(), s2 = O&#x5B;i+2];\r\n\t\tfor (int it = 0; it &lt; src-&gt;sz; it++){\r\n\t\t\ts0 = src-&gt;state&#x5B;it] &amp; _A | up, s1 = (src-&gt;state&#x5B;it] &amp; _B) &gt;&gt; _W;\r\n\t\t\tb = src-&gt;key&#x5B;it], dfs(0, 0, s1, s2);\r\n\t\t}\r\n\t\t\/\/cout &lt;&lt; des-&gt;sz &lt;&lt; endl;\r\n\t}\r\n\t\r\n\tans = 0;\r\n\tfor (int it = 0; it &lt; des-&gt;sz; it++)\r\n\t\tans = max(ans, des-&gt;key&#x5B;it]);\r\n}\r\n\r\nvoid init(){\r\n\tint t;\r\n\tscanf(&quot;%d%d%d&quot;, &amp;h, &amp;w, &amp;t); \r\n\tmemset(O, 0, sizeof(O));\r\n\t\r\n\tint x, y;\r\n\tfor (int i=0;i&lt;t;i++){\r\n\t\tscanf(&quot;%d%d&quot;, &amp;x, &amp;y), x--, y--;\r\n\t\tO&#x5B;x] |= 1 &lt;&lt; y;\r\n\t}\r\n\t\r\n\tup = 1 &lt;&lt; w;\r\n\tO&#x5B;h] = up - 1;\r\n}\r\n\r\n\r\nint main(){\r\n\t\/\/freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n\tint T; cin &gt;&gt; T;\r\n\twhile (T--){\r\n\t\tinit(); solve();\r\n\t\tcout &lt;&lt; ans &lt;&lt; endl;\r\n\t}\r\n}\r\n<\/pre>\n<h3>External link :<\/h3>\n<p><a href=\"http:\/\/poj.org\/problem?id=1038\">http:\/\/poj.org\/problem?id=1038<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description : \u7ed9\u5b9a\u4e00\u5757 n \u00d7 m \u7684\u7535\u8def\u677f\uff0c\u4e0a\u9762\u6709\u4e00\u4e9b\u4f4d\u7f6e\u662f\u574f\u7684\uff0c\u95ee\u6700\u591a\u53ef\u4ee5\u9576\u5d4c\u591a\u5c112 \u00d7 3\u5927\u5c0f\u7684\u82af\u7247\u3002 \uff081 &lt; = n &lt;= 150, 1 &lt;= m &lt;= 10 &#8230;\uff09<\/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":[1],"tags":[],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-1f","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/77","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=77"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}