{"id":174,"date":"2012-04-07T15:52:28","date_gmt":"2012-04-07T07:52:28","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=174"},"modified":"2012-04-12T16:56:23","modified_gmt":"2012-04-12T08:56:23","slug":"srm-538","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/srm-538\/","title":{"rendered":"SRM 538"},"content":{"rendered":"<p><!--more--><\/p>\n<h3>Brief description: <\/h3>\n<p>Level 3 \u53c8\u662f\u4e00\u4e2a\u5173\u4e8e\u5806\u7816\u7684\u89c6\u56fe\u95ee\u9898\uff0c\u611f\u89c9\u8fd9\u7c7b\u95ee\u9898\u561b\u3001\u7b97\u6cd5\u96be\u5ea6\u867d\u4e0d\u9ad8\u3002\u3002\u3002<br \/>\n\u4e0d\u8fc7\u5206\u6790\u8d77\u6765\u5b9e\u975e\u8f7b\u6613\uff0c\u82e5\u4e0d\u8fdb\u884c\u53ca\u65f6\u7684\u603b\u7ed3\uff0c\u5927\u6982\u4e0b\u6b21\u8fd8\u662f\u4f1a\u843d\u5165 &#8220;\u91cd\u4e0e\u6f0f&#8221; \u7684\u9677\u9631\u91cc\u3002\u3002\u3002<\/p>\n<p>\u4eca\u56de\u9898\u76ee\u662f\u4e2a\u4e8c\u7ef4\u7248\u672c\uff0c\u7816\u5757\u5206\u4e3a 1\u00d71 \u7684\u5f69\u8272 cubes \u548c 1\u00d72 \u7684\u9ed1\u8272 prisms\uff0c<br \/>\n\u3002\u3002|cubes| = n\u3001 Sigma{cubes[..]} = s\u3001\u9ed1\u7816\u6570\u76ee\u4e3a B\u3001\u5bbd\u5ea6\u4e3a W \u3002\u3002\u4e0d\u8981\u6c42\u6446\u653e\u5b8c\u3002\u3002<\/p>\n<p>DIV 2 1050 SkewedPerspectives:<br \/>\n\u5224\u5b9a\u7ed9\u5b9a\u89c6\u56fe\u7684\u5408\u6cd5\u6027\u3002\uff08n \u2264 3\u3001B \u2264 100\u3001W \u2264 50 .. .\uff09<br \/>\nDIV 1 1050 SkewedPerspective<br \/>\n\u5bf9\u6240\u6709\u53ef\u80fd\u89c6\u56fe\u8fdb\u884c\u8ba1\u6570\u3002\uff08n \u2264 50\u3001s \u2264 50\u3001B \u2264 10\u3001W \u2264 8 .. .\uff09<\/p>\n<pre> .. . Remember from the division 2 explanation that whenever we move to a new column to place a prism, \r\nit creates empty space that must be filled. \r\nThe empty space will be composed of two parts: \r\n\r\nfill1: This is the number of places that forcefully need cubes \r\n(remember that this happens when the empty space in a column is odd). \r\nWe need it to know the number of remaining cubes. \r\n\r\nfill2: The number of spaces of size 1x2. \r\nWhich we can eventually replace with a prism or 2 cubes each. .. <\/pre>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/apps.topcoder.com\/wiki\/download\/attachments\/75333911\/editorial_div21050_8.png\" alt=\".. as low as possible .\" \/><\/p>\n<p>\u4e24\u4e2a\u95ee\u9898\u4e00\u8d77\u770b\u662f\u6bd4\u8f83\u79d1\u5b66\u7684\uff0c\u8981\u89e3\u51b3\u8ba1\u6570\u95ee\u9898\u5927\u6982\u81f3\u5c11\u8981\u7406\u89e3\u5224\u5b9a\u7248\u672c\u7684\u95ee\u9898\uff0c\u89e3\u51b3\u5224\u5b9a\u95ee\u9898\u662f\u6ce8\u610f\u5230\u4e0a\u9762\u7684\u8bdd\u3002\u3002<br \/>\n\u5927\u6982\u7684\u542b\u4e49\u5982\u56fe\u6240\u793a\uff0c\u603b\u662f\u5c31\u662f\u8981\u5c3d\u91cf\u672c\u7740\u7528\u6599\u8282\u7701\u7684\u539f\u5219\u3002<\/p>\n<p>&#8230;<\/p>\n<pre class=\"brush: cpp; light: false; title: DIV 2 1050. SkewedPerspectives; toolbar: true; notranslate\" title=\"DIV 2 1050. SkewedPerspectives\">\r\n.. .\r\nconst int MOD = 1000000007;\r\nconst int INF = 0x7fffffff;\r\n\r\nconst int N = 50;\r\n\r\nint cubes&#x5B;3], B, W;\r\n\r\nbool check(string view){\r\n\r\n    int h = SZ(view), b = B, w = W - 1, c&#x5B;3]; CPY(c, cubes);\r\n    int f0 = 0, f1 = 0;\r\n\r\n    if (view&#x5B;0] == 'b' &amp;&amp; (SZ(view) == 1 || view&#x5B;1] != 'b')) return false;\r\n\r\n    REP(i, h) if (view&#x5B;i] == 'b'){\r\n        int _i = i++;\r\n        while (i &lt; SZ(view) &amp;&amp; view&#x5B;i] == 'b') ++i;\r\n        int len = (i--) - _i;\r\n        b -= (len + 1) \/ 2;\r\n        if (len&amp;1){\r\n            --w, f0 += abs(_i - 1);\r\n            if ((_i-1)&amp;1) ++f1;\r\n        }\r\n    }\r\n    else{\r\n        --c&#x5B;view&#x5B;i]-'0'];\r\n    }\r\n\r\n    if (c&#x5B;0] &lt; 0 || c&#x5B;1] &lt; 0 || c&#x5B;2] &lt; 0 || b &lt; 0 || w &lt; 0) return false;\r\n    int s = c&#x5B;0] + c&#x5B;1] + c&#x5B;2];\r\n    if (s &lt; f1 || s + b*2 &lt; f0) return false;\r\n    return true;\r\n}\r\n\r\n\r\nclass SkewedPerspectives {\r\npublic:\r\n\tvector &lt;string&gt; areTheyPossible(vector &lt;int&gt; _cubes, int _B, int _W, vector &lt;string&gt; views) {\r\n\r\n\t    B = _B, W = _W; cubes&#x5B;0] = _cubes&#x5B;0], cubes&#x5B;1] = _cubes&#x5B;1], cubes&#x5B;2] = _cubes&#x5B;2];\r\n\r\n\t\tvector&lt;string&gt; res; REP(i, SZ(views)) res.PB(check(views&#x5B;i]) ? &quot;valid&quot; : &quot;invalid&quot;);\r\n\r\n\t\treturn res;\r\n\t}\r\n};\r\n<\/pre>\n<p>\u5bf9\u4e8e\u5224\u5b9a\u7248\u672c\u7684\u95ee\u9898\uff0c\u5c06 Cubes \u5f53\u505a\u6574\u4f53\u6765\u5904\u7406\u8fd8\u53ef\u505a\u53ef\u4e0d\u505a\u7684\u8bdd\uff0c\u4f46\u662f\u8ba1\u6570\u7248\u672c\u5c31\u4e0d\u80fd\u9000\u8ba9\u4e86\u3002<br \/>\n\u5148\u7528\u52a8\u6001\u89c4\u5212\u548c\u4e8c\u9879\u5f0f\u7cfb\u6570\u505a\u51fa\u8f85\u52a9\u6570\u7ec4 G\u3002<\/p>\n<pre>\r\nG[i]: \u4ece\u6240\u6709 Cubes \u4e2d\uff0c\u9009\u51fa i \u4e2a\u6392\u6210\u4e00\u884c\uff0c\u989c\u8272\u4e0d\u540c\u7684\u65b9\u6cd5\u6570\u3002\r\n<\/pre>\n<p>\u3002\u3002\u6700\u5927\u7684\u96be\u70b9\u662f\u62bd\u8c61\u51fa\u63a5\u4e0b\u6765\u8981\u63a8\u7684\u72b6\u6001\u3002\u3002\u3002<\/p>\n<p>\u9996\u5148\u5df2\u7ecf\u5b9a\u4e49\u4f7f\u7528\u7684 Cubes \u6570\u4e3a nn\u3001<br \/>\n\u51fa\u73b0\u7684\u5355\u683c\u7684\u9ed1\u7816\u6570\u4e3a b1\uff08\u4ec5\u5728\u6b64\u60c5\u51b5\u4e0b\u9700\u8981\u5207\u884c\uff09\u3001<br \/>\n\u53cc\u683c\u9ed1\u7816\u6570\u4e3a b2 \u3002\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u8003\u8651\u586b\u5751\u7684\u95ee\u9898\u3002\u3002\u3002<\/p>\n<pre>\r\nf0: \u9700\u8981\u586b\u7684\u5751\u7684\u603b\u6570\u3002 \r\nf1: \u5176\u4e2d\u5fc5\u987b\u7528 cubes \u586b\u7684\u5751\u3002\r\nf2: \u5176\u4e2d\u53ef\u4ee5\u7528 prisms \u586b\u7684\u5751\u3002\r\n<\/pre>\n<p>\u3002\u3002\u77e5\u4e8c\u6c42\u4e09\uff0c\u8282\u7701\u8d77\u89c1\u5c31\u5b58 f1\u3001f2\uff08.. .f1 < W .. . 2f2 \u2264 2B + n .. .\uff09\u3002\u3002\u3002\n\u6b64\u5916\u540c\u5224\u5b9a\u95ee\u9898\u4e00\u6837\u8fd9\u91cc\u4ecd\u7136\u9700\u8981\u8003\u8651\u6446\u653e b1 \u65f6\u7684\u9650\u5236\u95ee\u9898\u3001\u9700\u8981\u52a0\u4e00\u7ef4\u72b6\u6001\u63cf\u8ff0\u6700\u540e\u586b\u7684\u662f\u5426\u662f\u9ed1\u7816\u3002(bool bk)\u3002\u3002\u3002\n\n\u4e8e\u662f\u603b\u7684\u72b6\u6001\u5c31\u662f\uff1a\n\n\n<pre>\r\n&#8230;\r\nconst int N = 50, BB = 10, WW = 8;\r\n.. .\r\nint F[N+1][WW][BB+1][WW][N\/2+BB+1][2];\r\n.. .\r\nconst int Null = -1;\r\n\r\nint f(int nn = 0, int b1 = 0, int b2 = 0, int f1 = 0, int f2 = 0, bool bk = false){\r\n\r\n    int &#038;res = F[nn][b1][b2][f1][f2][bk];\r\n\r\n    while (res == Null){\r\n       .. .\r\n    }\r\n\r\n    return res;\r\n}\r\n<\/pre>\n<p>\u6700\u540e\u72b6\u6001\u8f6c\u79fb\u8f6c\u79fb\u5206 nn+1\u3001b1+1\u3001b2+1 \u4e09\u79cd\u60c5\u51b5\u8ba8\u8bba\u5373\u53ef\u3002\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: DIV 1 1050. SkewedPerspective; toolbar: true; notranslate\" title=\"DIV 1 1050. SkewedPerspective\">\r\nconst int N = 50, BB = 10, WW = 8;\r\n\r\nint B, W; VI cubes;\r\n\r\nint F&#x5B;N+1]&#x5B;WW]&#x5B;BB+1]&#x5B;WW]&#x5B;N\/2+BB+1]&#x5B;2], G&#x5B;N+1], C&#x5B;N+1]&#x5B;N+1], tmp&#x5B;N+1]&#x5B;N+1];\r\nint n, s;\r\n\r\nconst int Null = -1;\r\n\r\nint f(int nn = 0, int b1 = 0, int b2 = 0, int f1 = 0, int f2 = 0, bool bk = false){\r\n\r\n    int &amp;res = F&#x5B;nn]&#x5B;b1]&#x5B;b2]&#x5B;f1]&#x5B;f2]&#x5B;bk];\r\n\r\n    while (res == Null){\r\n\r\n        res = 0; int rs = s-nn-f1, rb = B-b1-b2;\r\n        if (rb &lt; 0 || rs &lt; 0 || b1 &gt;= W || rs\/2 + rb &lt; f2) break;\r\n        int h = nn + b1 + 2*b2;\r\n\r\n        if (h) INC(res, G&#x5B;nn]);\r\n\r\n        if (rs) INC(res, f(nn+1, b1, b2, f1, f2, false));\r\n        if (rb){\r\n            INC(res, f(nn, b1, b2+1, f1, f2, true));\r\n            if (h&amp;&amp;(!bk||h==2&amp;&amp;b2==1)) INC(res, f(nn, b1+1, b2, f1+((h-1)&amp;1), f2+(h-1)\/2, true));\r\n        }\r\n    }\r\n\r\n    return res;\r\n}\r\n\r\nclass SkewedPerspective{\r\npublic:\r\n\tint countThem(vector &lt;int&gt; _cubes, int _B, int _W){\r\n\r\n\t    B = _B, W = _W, cubes = _cubes, n = SZ(cubes), s = accumulate(ALL(cubes), 0);\r\n\r\n\t    RST(C); FOR_1(i, 0, s){C&#x5B;i]&#x5B;0] = 1; REP_1(j, i) C&#x5B;i]&#x5B;j] = sum(C&#x5B;i-1]&#x5B;j-1], C&#x5B;i-1]&#x5B;j]);}\r\n\r\n\t    RST(tmp); tmp&#x5B;0]&#x5B;0] = 1; REP_1(i, n) FOR_1(j, 0, s) FOR_1_C(k, 0, min(cubes&#x5B;i-1], j)) INC(tmp&#x5B;i]&#x5B;j], pdt(C&#x5B;j]&#x5B;k], tmp&#x5B;i-1]&#x5B;j-k]));\r\n\r\n\t    CPY(G, tmp&#x5B;n]); FLC(F, Null);\r\n\r\n\t\treturn f();\r\n\t}\r\n};\r\n<\/pre>\n<h3>External link: <\/h3>\n<p><a href=\"http:\/\/apps.topcoder.com\/wiki\/display\/tc\/SRM+538\">http:\/\/apps.topcoder.com\/wiki\/display\/tc\/SRM+538<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"","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":[65],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-topcoder","tag-65"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-2O","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/174","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=174"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/174\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}