{"id":186,"date":"2012-04-22T02:05:13","date_gmt":"2012-04-21T18:05:13","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=186"},"modified":"2012-05-04T01:15:54","modified_gmt":"2012-05-03T17:15:54","slug":"tco-2012-round-2a","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/tco-2012-round-2a\/","title":{"rendered":"TCO 2012 Round 2A"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>300: SwitchesAndLamps:<br \/>\n\u3002\u3002\u7ed9\u5b9a n \u7ec4\u5f00\u5173\u548c\u706f\u6ce1\uff0c\u4ee5\u53ca m \u7ec4\u5f00\u5173\u4e0e\u706f\u6ce1\u7684\u5bf9\u5e94\u5173\u7cfb\uff0c(\u4ee5\u5b50\u96c6\u7684\u65b9\u5f0f\u7ed9\u51fa)\u3002\u3002<br \/>\n\u95ee\u81f3\u5c11\u518d\u6dfb\u52a0\u591a\u5c11\u7ec4\uff0c\u53ef\u4ee5\u4e00\u4e00\u786e\u5b9a\u5f00\u5173\u4e0e\u706f\u6ce1\u7684\u5bf9\u5e94\u5173\u7cfb.. .<br \/>\n.. .( .. n, m \u2264 50 .. ) .. .<\/p>\n<p>450: CucumberWatering<br \/>\n\u3002\u3002\u67d0\u4eba\u8981\u6309\u7167\u987a\u5e8f\u7ecf\u8fc7\u6570\u8f74\u4e0a\u7684 n \u4e2a\u70b9 ( \u6709\u8fd4\u56de\u73b0\u8c61\uff0c\u4e0d\u4fdd\u8bc1\u9012\u589e)\u3002\u3002<br \/>\n\u3002\u95ee\u5728\u53ef\u4ee5\u5b89\u7f6e m \u4e2a\u4f20\u9001\u95e8\u7684\u60c5\u51b5\u65f6\u7684\u6700\u5c0f\u4ee3\u4ef7\u3002\u3002( \u7ecf\u8fc7\u4e00\u4e2a\u4f20\u9001\u95e8\u53ef\u4ee5\u9009\u62e9\u4ece\u4efb\u610f\u4e00\u4e2a\u4f20\u9001\u95e8\u51fa\u6765\u3002\u3002)<br \/>\n.. .( .. n, m \u2264 50 .. ) .. .<\/p>\n<p>1000: EvenPaths<br \/>\n\u3002\u3002\u7ed9\u5b9a\u4e00\u4e2a \u6709 n \u4e2a\u70b9\u7684 DAG \u3002\u3002\u5176\u4e2d\u6709 m \u4e2a\u70b9\u662f\u53ef\u4ee5\u5c01\u95ed\u7684\u3002\u3002<br \/>\n\u3002\u3002\u5f53\u4ece 0 \u51fa\u53d1\u5230 1 \u7684\u8def\u5f84\u603b\u6570\u662f\u5076\u6570\u7684\u65f6\u5019\u90a3\u4e48\u79f0\u4e4b\u4e3a Nice \u7684\u3002\u3002\u3002\u95ee Among \u8fd9 2^m \u79cd\u72b6\u6001\u4e2d\uff0c\u6709\u591a\u5c11\u79cd\u662f Nice \u7684\u3002\u3002<\/p>\n<p><!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>\u8fd9\u76d8\u6309\u7167 450->300->1000 \u7684\u987a\u5e8f\u3002\u3002<\/p>\n<p>\u9996\u5148 450 \u51fa\u4e86\u5f88\u5927\u7684\u95ee\u9898\u3002\u3002\u3002\u9996\u5148\u6211\u4e5f\u610f\u8bc6\u5230\u4e86\u89e3\u7684\u79bb\u6563\u6027\u3002\u3002\u4f46\u6211\u72af\u7684\u9519\u8bef\u662f\u3002\u3002\u603b\u662f\u7ea0\u7ed3\u5bf9\u6570\u8f74\u4e0a\u7684 n \u4e2a\u70b9\u662f\u4fdd\u7559\u6392\u5e8f\u540e\u7684\uff0c\u8fd8\u662f\u4e0d\u6392\u5e8f\u7684\u3002\u3002\u3002<br \/>\n\u3002\u3002\u3002( \u4f46\u5176\u5b9e\u662f\u4e24\u4e2a\u90fd\u8981\u4fdd\u7559\u3002\u3002) \u518d\u4e4b\u540e\u5c31\u662f\u5bf9 w \u6570\u7ec4\u9519\u8bef\u8ba4\u8bc6\u3002\u3002\u3002(\u3002\u3002\u4e00\u76f4\u8ba4\u4e3a\u8981\u4ece\u6bcf\u5bf9\u4f20\u9001\u95e8\u7684\u89d2\u5ea6\u3002\u3002\u6765\u677e\u5f1b\u8def\u5f84\u5bfc\u81f4\u65e0\u6cd5\u4e66\u5199\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u3002\u3002)<\/p>\n<p>\u53e6\u5916\u72af\u7684\u9519\u3002\u3002\u5728\u660e\u660e\u77e5\u9053\u662f\u52a8\u6001\u89c4\u5212\u4f46\u662f\u4e0d\u4f1a\u52a8\u6001\u89c4\u5212\u7684\u65f6\u5019\u8fd8\u53bb\u60f3\u4e86\u4e2a\u8d2a\u5fc3\u3002\u3002\u3002( \u5c45\u7136\u8fd8\u8c03\u5bf9\u4e86\u6837\u4f8b\u3002\u3002\u3002\u4f46\u662f\u660e\u663e\u662f\u9519\u7684\u3002\u3002\u4e0d\u613f\u4ea4\u3002\u3002Orz\u3002)\u3002\u3002\u3002\u5176\u5b9e\u603b\u7684\u8bf4\u6765 450 \u662f\u4e00\u4e2a\u6bd4\u8f83\u5e38\u89c4\u7684 2D\/1D DP\u3002\u3002(\u3002\u3002\u72b6\u6001\u4e24\u7ef4, \u679a\u4e3e\u72b6\u6001\u8f6c\u79fb 1 \u7ef4\u3002\u3002\u53e6\u5916 w \u6570\u7ec4\u597d\u50cf\u53ef\u4ee5 O(n2) \u9884\u5904\u7406\u3002\u3002\u3002)\u3002\u3002\u3002<\/p>\n<p>\u6700\u540e\u7559\u4e86 25 \u5206\u949f\u505a 300\u3002\u3002\u5176\u5b9e 300 \u60f3\u7684\u65b9\u6cd5\u5176\u5b9e\u8fd8\u662f\u6bd4\u8f83\u597d\u7684\u3002\u3002\u5199\u4e86\u4e00\u4e2a\u5f88\u4f18\u7f8e\u7684\u9012\u5f52\u3002\u3002( \u907f\u514d\u4e86\u4e8c\u5206\u56fe\u5339\u914d\u3002\u3002)\u3002\u3002<br \/>\n (\u3002\u3002<a href=\"http:\/\/community.topcoder.com\/stat?c=coder_room_stats&#038;rd=15093&#038;cr=22727863\">\u73b0\u573a\u751f\u4ee3\u7801<\/a> \u80e1\u4e71 yy \u4e86\u4e00\u4e2a\u5bf9\u79f0\u7684\u4f4d\u8fd0\u7b97\u8868\u8fbe\u5f0f\u8c03\u8fc7\u4e86\u6837\u4f8b\u5c45\u7136\u5c31\u4ea4\u4e86\u3002\u3002\u3002)\u3002\u3002\u5176\u5b9e\u6b63\u786e\u7684\u65b9\u6cd5\u53ea\u8981\u5224\u65ad count_bits(s) != count_bits(l) \u5c31\u884c\u4e86\u3002\u3002\u3002= =\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: SwitchesAndLamps; toolbar: true; notranslate\" title=\"SwitchesAndLamps\">\r\nconst int MOD = 1000000007;\r\nconst int INF = 0x7fffffff;\r\n\r\nconst int N = 50;\r\n\r\ninline bool _1(LL x, int i){return x &amp;amp; 1LL&amp;lt;&amp;lt;i;}\r\ninline LL _1(int i){return 1LL&amp;lt;&amp;lt;i;}\r\ninline LL _U(int i){return _1(i) - 1;};\r\n\r\nvector &amp;lt;string&amp;gt; S, L; int n, m;\r\nint res; bool Bad;\r\n\r\nint count_bits(LL mask){\r\n    int res = 0; REP(i, n) if (_1(mask, i)) ++res;\r\n    return res;\r\n}\r\n\r\nvoid Gao(int k = 0, LL s = _U(n), LL l = _U(n)){\r\n\r\n    if (Bad) return; if (count_bits(s) != count_bits(l)){Bad = true; return;}\r\n    if (count_bits(s) &amp;lt;= 1) return;\r\n\r\n    if (k == m) checkMax(res, count_bits(s));\r\n    else {\r\n        LL _s = 0, s_ = 0, _l = 0, l_ = 0; REP(i, n){\r\n            if (S&#x5B;k]&#x5B;i] == 'Y') _s |= _1(i);\r\n            if (L&#x5B;k]&#x5B;i] == 'Y') _l |= _1(i);\r\n        }\r\n\r\n        s_ = ~_s, l_ = ~_l;\r\n\r\n        Gao(k + 1, s &amp;amp; _s, l &amp;amp; _l );\r\n        Gao(k + 1, s &amp;amp; s_, l &amp;amp; l_);\r\n    }\r\n}\r\n\r\nclass SwitchesAndLamps {\r\npublic:\r\n  int theMin(vector &amp;lt;string&amp;gt; switches, vector &amp;lt;string&amp;gt; lamps) {\r\n        S = switches, L = lamps, n = SZ(L&#x5B;0]), m = SZ(L);\r\n        res = 1; Bad = false; Gao();\r\n        return Bad ? -1 : int(ceil(log2(res)));\r\n  }\r\n};\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: CucumberWatering; toolbar: true; notranslate\" title=\"CucumberWatering\">\r\nconst LL INF = (1LL &lt;&lt; 60);\r\nconst int Null = -1;\r\n\r\nstruct CucumberWatering{\r\n\r\n    vector&lt;LL&gt; P; vector&lt;pair&lt;LL, LL&gt; &gt; L;\r\n    LL _F&#x5B;52]&#x5B;51], _W&#x5B;50]&#x5B;50]; int n;\r\n\r\n    LL w(int l, int r){\r\n        LL &amp;W = _W&#x5B;l]&#x5B;r]; if (W == Null){\r\n            LL a = P&#x5B;l], b = P&#x5B;r]; W = 0; ECH(q, L) {\r\n                LL c = q-&gt;first, d = q-&gt;second;\r\n                if ((a &lt;= c &amp;&amp; c &lt;= b) &amp;&amp; (a &lt;= d &amp;&amp; d &lt;= b)) W += min(d - c, (c - a) + (b - d));\r\n                else if (a &lt;= c &amp;&amp; c &lt;= b) W += min(c - a, b - c);\r\n                else if (a &lt;= d &amp;&amp; d &lt;= b) W += min(d - a, b - d);\r\n            }\r\n        }\r\n        return W;\r\n    }\r\n\r\n    LL f(int l, int remK){\r\n        LL &amp;F = _F&#x5B;l]&#x5B;remK]; if (F == Null){\r\n            F = w(l, n+1);\r\n            if (remK != 0) FOR_1(i, l+1, n)\r\n                checkMin(F, w(l, i) + f(i, remK-1));\r\n        }\r\n        return F;\r\n    }\r\n\r\n    LL theMin(vector &lt;int&gt; X, int K){\r\n        n = SZ(X); ECH(it, X) P.PB(*it); P.PB(-INF), P.PB(+INF), SRT(P);\r\n        FOR(i, 1, n) L.PB(MP(min(X&#x5B;i], X&#x5B;i-1]), max(X&#x5B;i], X&#x5B;i-1]))); FLC(_F, _W, -1);\r\n        return f(0, K);\r\n    }\r\n};\r\n<\/pre>\n<p>\u3002\u3002\u3002\u3002\u30022B \u518d\u6765\u8fc7\u5427\u3002\u3002\u3002\u3002 \/$:o~o <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: 300: SwitchesAndLamps: \u3002\u3002\u7ed9\u5b9a n \u7ec4\u5f00\u5173\u548c\u706f\u6ce1\uff0c\u4ee5\u53ca m \u7ec4\u5f00\u5173\u4e0e\u706f\u6ce1\u7684\u5bf9\u5e94\u5173\u7cfb\uff0c(\u4ee5\u5b50\u96c6\u7684\u65b9\u5f0f\u7ed9\u51fa)\u3002\u3002 \u95ee\u81f3\u5c11\u518d\u6dfb\u52a0\u591a\u5c11\u7ec4\uff0c\u53ef\u4ee5\u4e00\u4e00\u786e\u5b9a\u5f00\u5173\u4e0e\u706f\u6ce1\u7684\u5bf9\u5e94\u5173\u7cfb.. . .. .( .. n, m \u2264 50 .. ) .. . 450: CucumberWatering \u3002\u3002\u67d0\u4eba\u8981\u6309\u7167\u987a\u5e8f\u7ecf\u8fc7\u6570\u8f74\u4e0a\u7684 n \u4e2a\u70b9 ( \u6709\u8fd4\u56de\u73b0\u8c61\uff0c\u4e0d\u4fdd\u8bc1\u9012\u589e)\u3002\u3002 \u3002\u95ee\u5728\u53ef\u4ee5\u5b89\u7f6e m \u4e2a\u4f20\u9001\u95e8\u7684\u60c5\u51b5\u65f6\u7684\u6700\u5c0f\u4ee3\u4ef7\u3002\u3002( \u7ecf\u8fc7\u4e00\u4e2a\u4f20\u9001\u95e8\u53ef\u4ee5\u9009\u62e9\u4ece\u4efb\u610f\u4e00\u4e2a\u4f20\u9001\u95e8\u51fa\u6765\u3002\u3002) .. .( .. n, m \u2264 50 .. ) .. . 1000: EvenPaths \u3002\u3002\u7ed9\u5b9a\u4e00\u4e2a \u6709 n \u4e2a\u70b9\u7684 DAG \u3002\u3002\u5176\u4e2d\u6709 m \u4e2a\u70b9\u662f\u53ef\u4ee5\u5c01\u95ed\u7684\u3002\u3002 \u3002\u3002\u5f53\u4ece [&hellip;]<\/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":[17],"tags":[],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-topcoder"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-30","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/186","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=186"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":207,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/186\/revisions\/207"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}