{"id":891,"date":"2014-05-27T20:03:38","date_gmt":"2014-05-27T12:03:38","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=891"},"modified":"2015-08-29T07:31:02","modified_gmt":"2015-08-28T23:31:02","slug":"srm-519","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/srm-519\/","title":{"rendered":"SRM 619"},"content":{"rendered":"<p><!--more--><\/p>\n<h2>600. GoodCompanyDivOne<\/h2>\n<h3>Brief description:<\/h3>\n<p>\u67d0\u516c\u53f8\u7684\u4eba\u5458\u4ece\u5c5e\u5173\u7cfb\u662f\u4e00\u9897\u6709\u6839\u6811\uff0c\u6709 N \u4e2a\u6280\u80fd\uff0c\u6bcf\u4e2a\u6280\u80fd\u7684\u5b66\u4e60\u8d39\u7528\u662f w[i]\uff0c\u6bcf\u4e2a\u7ed3\u70b9\u548c\u5176\u6240\u6709\u5b69\u5b50\u7ec4\u6210\u4e00\u4e2a\u90e8\u95e8\uff08department)\uff0c\u8981\u6c42\u6bcf\u4e2a\u90e8\u95e8\u7684\u6240\u6709\u4eba\u5458\u6240\u4ece\u4e8b\u7684\u5de5\u4f5c\u4e0d\u540c\uff0c\u6bcf\u4e2a\u4eba\u9700\u8981\u5b66\u4e60\u6070\u597d\u4e24\u4e2a\u6280\u80fd\uff0c\u53ea\u6709\u5728\u5b66\u4e60\u4e86\u6280\u80fd i \u7684\u60c5\u51b5\u4e0b\u624d\u53ef\u4ee5\u4ece\u4e8b\u5de5\u4f5c i\uff0c\u6ce8\u610f department \u4e4b\u95f4\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u4e00\u4e2a\u4eba\u53ef\u4ee5\u5728\u4e0d\u540c\u7684 department \u4e2d\u4ece\u4e8b\u4e0d\u540c\u7684\u5de5\u4f5c\u3002<\/p>\n<h3>Analysis:<\/h3>\n<p>Tree DP + KM\u3002\u3002\u3002<br \/>\n\u7b97\u6cd5\u663e\u7136\u3002\u3002\u3002<\/p>\n<p>\u5bf9\u4e8e\u7ed3\u70b9 u \u4e3a\u6839\u7684 department\u3002\u3002\u8bbe dp[u][x] \u8868\u793a\u8be5\u7ed3\u70b9\u4ece\u4e8b\u5de5\u4f5c x \u65f6\uff0c\u6574\u4e2a\u4ee5 u \u4e3a\u6839\u7684\u5b50\u6811\u7684\u6700\u5c11\u4ee3\u4ef7\u3002\u3002\u3002<br \/>\n \u3002\u901a\u8fc7\u5bf9\u5b50\u6811\u7684\u9012\u5f52\u5f97\u5230\u6bcf\u4e2a\u5b69\u5b50\u4ece\u4e8b\u5404\u4e2a\u5de5\u4f5c\u65f6\u7684\u4ee3\u4ef7\u3002\u3002<br \/>\n \u3002 \u3002\u518d\u679a\u4e3e u \u6240\u4ece\u4e8b\u7684\u5de5\u4f5c\u3002\u3002\u5219\u53ef\u4ee5\u901a\u8fc7\u5339\u914d\u8ba1\u7b97\u6700\u4f18\u89e3\u3002\u3002\u3002<\/p>\n<p>\u8fd9\u91cc\u4e3b\u8981\u6765\u89e3\u51b3\u5f53\u65f6\u6211\u7684\u4e00\u4e2a\u9057\u7559\u95ee\u9898\u3002\u3002\u3002<br \/>\n\u3002\u3002\u3002\u3002\u5bf9\u4e8e u \u6b64\u65f6\u6240\u4ece\u4e8b\u7684\u5de5\u4f5c\u3002\u8fd9\u4e2a\u6280\u80fd\u662f\u5fc5\u987b\u5b66\u4e60\u7684\u3002\u3002\u9664\u6b64\u4e4b\u5916\u8fd8\u9700\u8981\u679a\u4e3e\u53e6\u4e00\u4e2a\u6280\u80fd\u6765\u66f4\u65b0\u4e0e\u8be5\u6280\u80fd\u76f8\u5173\u7684 dp \u503c\u3002\u3002<br \/>\n\u3002\u3002\u901a\u8fc7\u679a\u4e3e\u8fd9\u4e2a\u3002\u3002\u5c06\u66f4\u65b0\u53e6\u4e00\u4e2a dp \u503c\u3002\u3002\u3002<\/p>\n<p>\u3002\u3002\u3002\u73b0\u573a\u751f\u7684\u65f6\u5019\u6211\u4e00\u5ea6\u8ba4\u4e3a\u3002\u3002\u3002\u53ea\u9700\u8981\u679a\u4e3e\u6bcf\u4e2a\u7ed3\u70b9\u4ece\u4e8b\u7684\u5de5\u4f5c x\u3002\u3002\u3002\u8fd9\u4e2a\u9644\u5e26\u7684\u6280\u80fd\u53d6 x \u4e4b\u5916 cheapest \u7684\u90a3\u4e2a\u5c31\u53ef\u4ee5\u4e86\u3002\u3002<br \/>\n\u3002\u3002\u63d0\u4ea4\u524d\u53c8\u628a\u8fd9\u4e2a\u6539\u56de\u6765\u4e86\u3002\u3002\uff08\u53cd\u6b63\u4e24\u8005\u590d\u6742\u5ea6\u4e00\u6837\u3002\u3002\u3002\uff09<\/p>\n<p>\u3002\u3002\u4e0d\u8fc7\u540e\u6765\u53c8\u8fd8\u539f\u56de\u53bb\u4ea4\u4e86\u4e00\u4e0b\u3002\u3002\u3002\u4e5f\u662f\u5bf9\u7684\u3002\u3002\u3002\u73b0\u5728\u6211\u6765\u8bd5\u56fe\u8bc1\u660e\u8fd9\u4e2a\u7ed3\u8bba\u3002\u3002\u3002\u3002<br \/>\n\u3010\u6570\u5b66\u5f52\u7eb3\u3011\u3010\u66ff\u6362\u94fe\u3011\u3010\u65e0\u7a77\u9012\u964d\u3011<\/p>\n<pre>\n\u5f52\u7eb3\u8bc1\u660e\u3002\u3002\u3002trivial \u60c5\u51b5\u663e\u7136\u3002\u3002\n\n\u3002\u3002\u3002\u3002\u8003\u8651 r \u7ed3\u70b9\u7684\u67d0\u4e2a\u5b69\u5b50 u\u3002\u3002\u3002\u5047\u8bbe\u53d6 (w_x, w_y) \u65f6\u6bd4 (c_x, w_x) \u65f6\u66f4\u4f18\u3002\u3002\u3002\uff08\u8fd9\u91cc c_x \u662f\u9664 w_x \u4e4b\u5916 cheapest \u7684\u90a3\u4e2a\u3002\u3002\uff09\n\u90a3\u4e48\u56e0\u4e3a c_x   &lt;  w_y\u3002\u3002\u3002\u5219\u4e00\u5b9a u \u7684\u67d0\u4e2a\u5b69\u5b50 v \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u66f4\u4f18\u3002\u3002\n\n\u800c\u8fd9\u53ea\u80fd\u662f\u56e0\u4e3a\u5176\u9009\u5230\u4e86\u3002\u3002dp[v] [x]\u3002\u3002\u3002\n\n\u4e5f\u5c31\u662f                        \u6ca1\u6709                                   \u4f18\u3002\n(c_x , w_x)                                (w_x, w_y)\n       |                                                    |\ndp[v][bad]                                     dp[v][x]\n\n\n\u56e0\u4e3a w_y \u7684\u7a7a\u7f3a\u3002\u3002\u3002bad \u6700\u574f\u60c5\u51b5\u81f3\u5c11 = y\u3002\u3002\u3002\n\n\u6b64\u65f6 v \u7ed3\u70b9\u7684\u4ee3\u4ef7\u662f\u3002\u3002\n(c_y, w_y)       (c_x, w_x)\n\n\u3002\u3002\u56e0\u4e3a c_y &lt;= w_x \u3002\u3002\u4e0d\u80fd\u4fdd\u8bc1\u6b64\u65f6 u \u7ed3\u70b9\u53d6 (w_x, w_y) \u66f4\u4f18\u3002\u3002\u3002\n\u3002\u3002\u56e0\u6b64\u7ee7\u7eed\u770b v \u7ed3\u70b9\u7684\u5b69\u5b50 w\u3002\u3002\u3002\n\n\u4e5f\u5c31\u662f\u8981\u6c42\u3002\u3002\u3002\ndp[w][x]  &lt; dp[w][y]\n\n\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002\n\n\u3002\u3002\u3002\u53cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\u3002\u3002\u8fd9\u6761 \u201c\u66ff\u6362\u94fe\u201d \u5c06\u4f1a\u4ea7\u751f\u3002\u3002\u3002\n\n(c_x, w_x)   (w_x, w_y)\n(c_y, w_y)   (c_x, w_x)\n(c_y, w_x)   (c_y, w_y)\n(c_y, w_y)   (c_x, w_x)\n(c_y, w_x)   (c_y, w_y)\n...           \n\u8fd9\u6837\u7684\u5faa\u73af\u3002\u3002\u3002\n\u3002\u3002\u3002\u800c\u5728\u4efb\u4f55\u4e00\u5c42\u90fd\u4e0d\u4f1a\u51fa\u73b0 (w_x, w_y)  \u66f4\u4f18\u3002\u3002\u3002\u56e0\u6b64\u547d\u9898\u5f97\u8bc1\u3002\n<\/pre>\n<pre class=\"brush: cpp; light: false; title: KM; toolbar: true; notranslate\" title=\"KM\">\r\nconst int N = 31, M = 31;\r\nint n, m;\r\n\r\nnamespace KM{ \/\/ KM-\u6700\u4f18\u5339\u914d\r\n    typedef int weight_t;\r\n    const weight_t weight_MAX = INF;\r\n    const weight_t weight_MIN = -INF;\r\n\r\n    weight_t W&#x5B;N]&#x5B;N], lx&#x5B;N], ly&#x5B;M], slack&#x5B;M];\r\n    int px&#x5B;N], py&#x5B;M]; bool vx&#x5B;N], vy&#x5B;M];\r\n    int n;\r\n\r\n#define w(x, y) (lx&#x5B;x] + ly&#x5B;y] - W&#x5B;x]&#x5B;y])\r\n\r\n    bool dfs(int x){\r\n        vx&#x5B;x] = 1; REP(y, m) if (!vy&#x5B;y]){\r\n            if (!w(x, y)){ \/\/!\r\n                vy&#x5B;y] = 1; if (py&#x5B;y] == -1 || dfs(py&#x5B;y])){\r\n                    py&#x5B;y] = x, px&#x5B;x] = y;\r\n                    return 1;\r\n                }\r\n            }\r\n            else {\r\n                checkMin(slack&#x5B;y], w(x, y));\r\n            }\r\n        }\r\n        return 0;\r\n    }\r\n\r\n    weight_t run(){\r\n        if (n &gt; m) return INF;\r\n        FLC(px, py, -1), fill(lx, lx + n, weight_MIN), fill(ly, ly + m, 0);\r\n        REP_2(x, y, n, m) checkMax(lx&#x5B;x], W&#x5B;x]&#x5B;y]);\r\n\r\n        REP(x, n){\r\n            fill(slack, slack + m, weight_MAX); while (1){\r\n                fill(vx, vx + n, 0), fill(vy, vy + m, 0);\r\n                if (dfs(x)) break; weight_t d = weight_MAX;\r\n                REP(i, m)  if (!vy&#x5B;i]) checkMin(d, slack&#x5B;i]);\r\n                REP(i, n) if (vx&#x5B;i]) lx&#x5B;i] -= d;\r\n                REP(i, m) if (vy&#x5B;i]) ly&#x5B;i] += d; else slack&#x5B;i] -= d;\r\n            }\r\n        }\r\n        weight_t res = 0; REP(x, n){\r\n            if (W&#x5B;x]&#x5B;px&#x5B;x]] == -INF) return INF;\r\n            res += W&#x5B;x]&#x5B;px&#x5B;x]];\r\n        }\r\n        return -res;\r\n    }\r\n\r\n#undef w\r\n\r\n\/\/Interface.. . \/\/{\r\n    void add_node(int t&#x5B;]){\r\n        REP(i, m) W&#x5B;n]&#x5B;i] = -t&#x5B;i]; ++n;\r\n    }\r\n\r\n    void init(){\r\n        n = 0;\r\n    }\r\n} \/\/using namespace KM;\r\n\r\nint dp&#x5B;N]&#x5B;N], w&#x5B;N]; vector&lt;int&gt; adj&#x5B;N];\r\n\r\n#define v (*it)\r\nvoid dfs(int u = 0){\r\n    ECH(it, adj&#x5B;u]) dfs(v);\r\n    REP(i, m) dp&#x5B;u]&#x5B;i] = INF;\r\n    REP(i, m){\r\n        KM::init(); ECH(it, adj&#x5B;u]){\r\n            int t = dp&#x5B;v]&#x5B;i]; dp&#x5B;v]&#x5B;i] = INF;\r\n            KM::add_node(dp&#x5B;v]); dp&#x5B;v]&#x5B;i] = t;\r\n        }\r\n        int t = KM::run();\r\n        dp&#x5B;u]&#x5B;i] = w&#x5B;i] + t;\r\n    }\r\n}\r\n\r\nclass GoodCompanyDivOne {\r\npublic:\r\n\tint minimumCost(vector &lt;int&gt; superior, vector &lt;int&gt; training) {\r\n\t\tn = SZ(superior); REP(i, n) adj&#x5B;i].clear(); FOR(i, 1, n) adj&#x5B;superior&#x5B;i]].PB(i);\r\n\t\tm = SZ(training); SRT(training); w&#x5B;0] = training&#x5B;0] + training&#x5B;1]; FOR(i, 1, m) w&#x5B;i] = training&#x5B;0] + training&#x5B;i];\r\n        FLC(dp, -1); dfs(); int z = INF; REP(i, m) checkMin(z, dp&#x5B;0]&#x5B;i]); if(z==INF) z = -1;\r\n\t\treturn z;\r\n\t}\r\n};\r\n<\/pre>\n<h2>1000. SimilarSequencesAnother<\/h2>\n<h3>Brief description: <\/h3>\n<p>A \u4e32\u4e0e B \u4e32 k-\u76f8\u4f3c\u7684\u6761\u4ef6\u662f\u5206\u522b\u4ece\u4e24\u4e2a\u4e32\u4e2d\u5220\u9664\u81f3\u591a k \u4e2a\u5143\u7d20\u4e4b\u540e\u5f97\u5230\u7684\u4e32\u76f8\u7b49\u3002<br \/>\n\u3002\u3002\u73b0\u7ed9\u5b9a A\uff0cB \u4e32\u7684\u957f\u5ea6 n \u548c\u5b57\u7b26\u96c6\u7684\u5927\u5c0f m \u3002\u3002\u95ee\u6709\u591a\u5c11\u5bf9\u4e32 2-\u76f8\u4f3c\u3002\u3002\u3002<\/p>\n<h3>Analysis: <\/h3>\n<p>\u8fd9\u4e2a\u9898\u5b9e\u5728\u662f\u5341\u5206 Nice .\u3002\u3002\u3002\u8003\u9a8c\u5bf9\u72b6\u6001\u7684\u53cd\u590d\u63d0\u70bc\u3002\u3002\u3002<\/p>\n<pre>\n\u5148\u5f31\u5316\u3002\u3002\n\u8003\u8651 A \u4e32 B \u4e32\u5df2\u7ecf\u7ed9\u5b9a\u3002\u3002\u5224\u65ad\u662f\u5426\u53ef\u884c\u3002\u3002\u3002\n\u90a3\u4e48\u6211\u4eec\u6709 dp[N][N][3][3]\u3002\u3002\u6700\u540e [3][3] \u8868\u793a\u5220\u9664\u7684\u6b21\u6570\u3002\u3002\u3002\u5bf9\u4e8e\u56fa\u5b9a\u7684\u4e00\u4e2a\u4e32\u3002\u3002\u4ed6\u6700\u540e dp[N][N][3][3] \u7684\u7ed3\u679c\u662f\u56fa\u5b9a\u7684\u3002\u3002\u3002\n\u3002\u3002\u3002\u6211\u4eec\u628a\u90a3\u4e9b\u5408\u6cd5\u65b9\u6848\u76f8\u540c\u7684\u4e32\u7528\u540c\u4e00\u4e2a\u72b6\u6001\u8868\u793a\u3002\u3002\u3002\u72b6\u6001\u538b\u7f29\u3002\u3002\u3002\u3002\u4e5f\u5c31\u662f s = 1&lt;&lt;9 \u3002\u3002\u3002\u3002\n\n\n\u56de\u5230\u539f\u95ee\u9898\u3002\u3002\u3002\n....\u8bbe\u8ba1\u4e00\u4e2a\u6a21\u7cca\u7684\u72b6\u6001\u3002\u3002(i, j, s) \u8868\u793a\u3002\u3002\u3002\n\u5f53\u524d A \u4e32\u8003\u8651\u5230\u7b2c i \u4e2a\u4f4d\u7f6e\uff0c B \u4e32\u8003\u8651\u5230 j \u4e2a\u4f4d\u7f6e\u3002\u3002\u5f53\u524d\u5408\u6cd5\u72b6\u6001\u96c6\u5408\u662f s\u3002\u3002\u7684\u65b9\u6848\u6570\u3002\u3002\n\u3002\u3002\u3002\n\n\u3002\u3002\u3002\u8fd9\u6837\u8003\u8651\u540e j \u7ef4\u8bb0\u5f55\u7684\u4e1c\u897f\u8fc7\u591a\u3002\u3002\u3002\u5b9e\u9645\u6211\u4eec\u53ea\u9700\u8981\u8bb0\u5f55\u3002\u3002\u3002\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\n...                   a[i] \n... b[i-2] b[i-1] b[i] b[i+1] b[i+2] \n\n\u3002\u3002\u3002\u4e0e a[i] \u76f8\u90bb\u7684 5 \u4e2a b \u7684\u4f4d\u7f6e\u7684\u6570\u5c31\u591f\u4e86\u3002\uff08\u53ea\u9700\u8981\u4fdd\u5b58\u524d\u56db\u4e2a\u3002b[i+2] \u8f6c\u79fb\u7684\u65f6\u5019\u679a\u4e3e\u3002\u3002\u3002\n\n\u3002\u3002\u8fdb\u4e00\u6b65\u3002\u3002\u3002\u6211\u4eec\u5e76\u4e0d\u5173\u5fc3\u5979\u4eec\u5177\u4f53\u662f\u591a\u5c11\u3002\u3002\u3002\u800c\u53ea\u9700\u8981\u77e5\u9053\u5b83\u4eec\u4e4b\u95f4\u7684\u76f8\u5bf9\u5927\u5c0f\u5173\u7cfb\u3002\n\u3002\u3002\u3002\uff08\u3002\u3002\u9519\u4e86\uff0c\u6ca1\u6709\u76f8\u5bf9\u5927\u5c0f\u5173\u7cfb\u3002\u3002\u3002\u800c\u53ea\u6709\u662f\u5426\u76f8\u7b49\u7684\u5173\u7cfb\u3002\uff01\uff01\u3002\u3002\uff09\u3002\n\n\n\n\n\u4f8b\u5982\n3 3 2 5 4...\n\u6211\u4eec\u53ef\u4ee5\u7cbe\u7b80\u6210\n0 0 1 2 3 ...\n\n\n\u3002\u3002\u3002\u4e5f\u5c31\u662f\u7528 \u6700\u5c0f\u8868\u793a\u6cd5 \u538b\u7f29\u8fd9\u5219\u72b6\u6001\u3002\u3002\u3002\u628a m \u7684\u9650\u5236\u53bb\u6389\u3002\u3002\u3002\u3002\n\n\u8fd9\u6837\u603b\u7684\u72b6\u6001 (i, b, s)\u3002\u3002\u3002\n\u53ea\u6709 \u3002\u3002N * 4^4 * 2^9 \u79cd\u3002\u3002\u3002\uff08\u5b9e\u9645\u4e0a\u4e2d\u95f4\u90a3\u4e00\u7ef4\u7ecf\u8fc7\u6700\u5c0f\u8868\u793a\u6cd5\u4e4b\u540e\u3002\u3002\u8fdc\u8fbe\u4e0d\u5230 4^4 \u7684\u4e0a\u754c\u3002\u3002\uff09\n\u3002\u3002\u3002\u8f6c\u79fb\u9700\u8981\u5206\u522b\u679a\u4e3e b[i+2] \u548c a[i]\u3002\u3002\u3002\u590d\u6742\u5ea6 O(5^2)\u3002\u3002\u3002\u4e24\u4e2a\u8f6c\u79fb\u56e0\u5b50\u5206\u522b\u8bb0\u505a c1 \u548c c2\u3002\u3002\u3002\u3002\n\u5e76\u6839\u636e\u662f\u5426\u548c\u4e4b\u524d\u72b6\u6001\u4e2d\u7684\u67d0\u4e2a\u6570\u76f8\u540c\u8fdb\u884c\u8ba8\u8bba\u5373\u53ef\u3002\u3002c = b==up ? m-up : 1\u3002\u3002\u3002\n\u7d2f\u52a0\u3002\u3002if (ss) v += u*c1*c2;\n\n\u6ce8\u610f\u5982\u679c ss \u4e3a 0 \u90a3\u4e48\u8bf4\u660e\u4e0d\u5b58\u5728\u4efb\u610f\u4e00\u4e2a\u5408\u6cd5\u72b6\u6001\u3002\u3002\u3002\u76f4\u63a5\u8df3\u8fc7\u5373\u53ef\u3002\u3002\u3002\u6211\u5c45\u7136\u56e0\u4e3a\u8fd9\u4e2a\u539f\u56e0 SB \u8c03\u8bd5\u597d\u4e45\u3002\u3002\n<\/pre>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 109, M = 9;\r\nmap&lt;PII, Int&gt; dp&#x5B;2]; int _b&#x5B;5], b&#x5B;5], p, q;\r\n\r\nvoid decode(int x){\r\n    REP(i, 4) b&#x5B;i] = x%4, x\/=4;\r\n}\r\n\r\nint encode(){\r\n    int x = 0; DWN(i, 4, 0) x*=4,x+=b&#x5B;i];\r\n    return x;\r\n}\r\n\r\nvoid recode(){\r\n    MII H; int n = 0; FOR(i, 1, 5){\r\n        if (!CTN(H, _b&#x5B;i])) H&#x5B;_b&#x5B;i]] = n++;\r\n        b&#x5B;i-1] = H&#x5B;_b&#x5B;i]];\r\n    }\r\n}\r\n\r\nclass SimilarSequencesAnother {\r\npublic:\r\n\r\n    int getCount(int n, int m){\r\n\r\n        p = 0, q = 1; RST(b); CLR(dp&#x5B;p]); dp&#x5B;p]&#x5B;MP(1, encode())] = m;\r\n        b&#x5B;3] = 1; dp&#x5B;p]&#x5B;MP(1, encode())] = Int(m)*(m-1);\r\n\r\n#define u (it-&gt;se)\r\n#define v dp&#x5B;p]&#x5B;MP(ss, encode())]\r\n\r\n        DO(n){\r\n            swap(p, q); CLR(dp&#x5B;p]); ECH(it, dp&#x5B;q]) if (u){\r\n                int s = it-&gt;fi.fi; decode(it-&gt;fi.se); CPY(_b, b); int up1 = *max_element(b, b+4)+1; FOR_1_C_N(_b&#x5B;4], 0, up1){\r\n                    Int c1 = _b&#x5B;4] == up1 ? m-up1 : 1; recode();\r\n                    int up2 = max(_b&#x5B;4]+1, up1); FOR_1(a, 0, up2){\r\n                        Int c2 = a == up2 ? m-up2 : 1; int ss = 0; REP(i, 9) if (_1(s, i)){\r\n                            int x = i%3, y = i\/3; REP(dx, 2) REP(dy, 3){\r\n                                int xx = x+dx, yy = y+dy; if (xx &gt; 2 || yy &gt; 2) continue;\r\n                                if (dx || a == _b&#x5B;2-xx+yy]) ss |= _1(yy*3+xx);\r\n                            }\r\n                        }\r\n                        if (ss) v += u*c1*c2;\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n        Int res = 0; ECH(it, dp&#x5B;p]){\r\n            decode(it-&gt;fi.se); if (!b&#x5B;2] &amp;&amp; !b&#x5B;3]) res += u;\r\n        }\r\n\r\n        return res;\r\n    }\r\n};\r\n<\/pre>\n<h3>External link:<\/h3>\n<p><a href=\"https:\/\/apps.topcoder.com\/wiki\/display\/tc\/SRM+619\">https:\/\/apps.topcoder.com\/wiki\/display\/tc\/SRM+619<\/a><br \/>\n<a href=\"https:\/\/gist.github.com\/lychees\/028faa9c2b009fb7f297\">https:\/\/gist.github.com\/lychees\/028faa9c2b009fb7f297<\/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":[1],"tags":[],"class_list":["post-891","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-en","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/891","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=891"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/891\/revisions"}],"predecessor-version":[{"id":901,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/891\/revisions\/901"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}