{"id":279,"date":"2012-07-03T23:43:52","date_gmt":"2012-07-03T15:43:52","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=279"},"modified":"2012-07-04T01:30:52","modified_gmt":"2012-07-03T17:30:52","slug":"zerojudge-b179-%e7%a9%ba%e7%bd%90-cans","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/zerojudge-b179-%e7%a9%ba%e7%bd%90-cans\/","title":{"rendered":"ZeroJudge b179. \u7a7a\u7f50 Cans"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>&#8230; \u7ed9\u5b9a\u4e00\u4e2a\u521d\u59cb\u57fa\u56e0\uff0c\u57fa\u56e0\u6bcf\u8f6e\u6bcf\u6b21\u4f1a\u5728\u540e\u9762\u6dfb\u52a0 {a, b, c ,d} \u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u5f62\u6210 4 \u4e2a\u65b0\u57fa\u56e0\u3002\u65e7\u57fa\u56e0\u5728\u5206\u88c2\u8fc7\u540e\u4f1a\u635f\u5931\u7b2c\u4e00\u4e2a\u5b57\u7b26\u3002\u3002\u3002\u3002<br \/>\n\u6709 n \u7ec4\u6709\u5bb3\u57fa\u56e0\uff0c\u5982\u679c\u51fa\u73b0\u4e86\u6709\u5bb3\u57fa\u56e0\u4f5c\u4e3a\u5b50\u4e32\u5219\u4e22\u5165\u533b\u9662\u3002\u3002<br \/>\n\u5982\u679c\u4e00\u4e2a\u57fa\u56e0\u957f\u5ea6\u53d8\u4e3a 0 \u5219\u88ab\u4e22\u5165\u56de\u6536\u573a\u3002\u3002<br \/>\n\u95ee\u6700\u540e\u5206\u522b\u6709\u591a\u5c11\u57fa\u56e0\u4e22\u5165\u533b\u9662\u591a\u5c11\u57fa\u56e0\u4e22\u5165\u56de\u6536\u573a\u3002\u3002\u3002<br \/>\n( .. p <= 100, n <= 100, \u03a3 = {a,b,c,d} .. )\n\n<!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>dp[i][j][k] \u8868\u793a\u7ecf\u8fc7 i \u5929\uff0c\u5f53\u524d\u5728\u81ea\u52a8\u673a\u4e0a\u4f4d\u7f6e\u4e3a j\uff0c\u4e32\u7684\u5b9e\u9645\u957f\u5ea6\u4e3a k \u65f6\u7684\u72b6\u6001\u3002<\/p>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: ZeroJudge b179. \u7a7a\u7f50 Cans.cpp; toolbar: true; notranslate\" title=\"ZeroJudge b179. \u7a7a\u7f50 Cans.cpp\">\r\n\r\n\/**********************************************************************************\/\r\n\/*  Problem: b179 &quot;\u7a7a\u7f50 Cans&quot; from CSAPC'08 Problem Setter: Akira Nanase        *\/\r\n\/*  Language: CPP (2909 Bytes)                                                    *\/\r\n\/*  Result: AC judge by zeroserver@ZeroJudge                                      *\/\r\n\/*  Author: lychees at 2011-08-29 01:02:15                                        *\/\r\n\/**********************************************************************************\/\r\n\r\n\r\n\/** ` Micro Mezzo Macro Flation -- Overheated Economy ., **\/\r\n\r\n#include &lt;iostream&gt;\r\n#include &lt;cstdio&gt;\r\n#include &lt;cstring&gt;\r\n\r\nusing namespace std;\r\n\r\n#define REP(i, n) for (int i=0;i&lt;int(n);++i)\r\n#define FOR(i, a, b) for (int i=int(a);i&lt;int(b);++i)\r\n#define DWN(i, b, a) for (int i=int(b-1);i&gt;=int(a);--i)\r\n#define REP_C(i, n) for (int n____=int(n),i=0;i&lt;n____;++i)\r\n#define FOR_1(i, a, b) for (int i=int(a);i&lt;=int(b);++i)\r\n#define DO(n) while(n--)\r\n#define DO_C(n) int n____ = n; while(n____--)\r\n\r\ntemplate&lt;class T&gt; inline void RST(T &amp;A){memset(A, 0, sizeof(A));}\r\ntemplate&lt;class T0, class T1&gt; inline void RST(T0 &amp;A0, T1 &amp;A1){RST(A0), RST(A1);}\r\ntemplate&lt;class T&gt; inline void RD(T &amp;x){char c; for (c = getchar(); c &lt; '0'; c = getchar()); x = c - '0'; for (c = getchar(); c &gt;= '0'; c = getchar()) x = x * 10 + c - '0';}\r\ninline int RD(){ int x; RD(x); return x;}\r\n\r\nconst int MOD = 10007;\r\ninline void INC(int &amp;a, int b){a += b; if (a &gt;= MOD) a -= MOD;}\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int  N = 1510, M = 100, L = 102, Sigma = 26, SIGMA = 4;\r\nint dp&#x5B;2]&#x5B;N]&#x5B;L]; int trie&#x5B;N]&#x5B;Sigma], fail&#x5B;N], len&#x5B;N] = {1}, cnt&#x5B;N], visited&#x5B;N], u, cz, op, tot;\r\nchar str&#x5B;M]; int n, s;\r\n\/\/ AC-automation\r\n\r\n#define v trie&#x5B;u]&#x5B;c]\r\n#define f trie&#x5B;fail&#x5B;u]]&#x5B;c]\r\n#define Q visited\r\n\r\ninline int New_node(){\r\n    fail&#x5B;tot] = cnt&#x5B;tot] = 0, RST(trie&#x5B;tot]);\r\n    return tot++;\r\n}\r\n\r\ninline void Build(){\r\n    cz = op = u = 0; REP(c, Sigma) if (v) Q&#x5B;op++] = v;\r\n\r\n    while (cz &lt; op){\r\n        u = Q&#x5B;cz++]; REP(c, Sigma)\r\n        if (v) fail&#x5B;Q&#x5B;op++] = v] = f, cnt&#x5B;v] += cnt&#x5B;fail&#x5B;v]];\r\n        else v = f;\r\n    }\r\n}\r\n\r\n#define c str&#x5B;i] - 'a'\r\n\r\nbool _first;\r\ninline void Insert(){\r\n    u = 0; REP_C(i, strlen(str)){\r\n        if (cnt&#x5B;v]) return;  \/\/Prefix Cut ..\r\n        if (!v) len&#x5B;v = New_node()] = i + 1;\r\n        u = v;\r\n    }\r\n\r\n    if (_first) _first = false, dp&#x5B;0]&#x5B;s = u]&#x5B;len&#x5B;u]] = 1;\r\n    else ++cnt&#x5B;u];\r\n}\r\n\r\n#undef c\r\n#undef f\r\n\r\nvoid Init(){\r\n    RST(dp&#x5B;0], trie&#x5B;0]), tot = 1, _first = true, Insert(), RD(n);\r\n    DO_C(RD()) scanf(&quot;%s&quot;, str), Insert(); Build();\r\n}\r\n\r\n#define u Q&#x5B;i]\r\n#define f fail&#x5B;u]\r\n#define d dp&#x5B;q]&#x5B;u]&#x5B;j]\r\n\r\nvoid Run(){\r\n    op = 0; REP(i, tot) if (!cnt&#x5B;i]) Q&#x5B;op++] = i;\r\n\r\n    while (s &amp;&amp; !cnt&#x5B;s]) s = fail&#x5B;s];\r\n    if (s){puts(&quot;0 1&quot;); return;}\r\n\r\n    int p = 0, q, a = 0, b = 0;\r\n    DO(n){\r\n\r\n        q = p, p ^= 1, RST(dp&#x5B;p]);\r\n\r\n        REP(i, op) FOR_1(j, len&#x5B;u], 100) if (d){\r\n            REP(c, SIGMA) if (cnt&#x5B;v]) INC(b, d); else INC(dp&#x5B;p]&#x5B;v]&#x5B;j+1], d);\r\n            if (j &gt; len&#x5B;u]) INC(dp&#x5B;p]&#x5B;u]&#x5B;j-1], d);\r\n            else if (cnt&#x5B;f]) INC(b, d); else INC(dp&#x5B;p]&#x5B;f]&#x5B;j-1], d);\r\n        }\r\n        INC(a, dp&#x5B;p]&#x5B;0]&#x5B;0]);\r\n    }\r\n\r\n\r\n   printf(&quot;%d %d\\n&quot;, a, b);\r\n}\r\n\r\n\r\nint main(){\r\n\r\n    \/\/freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n\r\n    while (scanf(&quot;%s&quot;, str) != EOF){\r\n        Init(); Run();\r\n    }\r\n}\r\n<\/pre>\n<h3>External link: <\/h3>\n<p><a href=\"http:\/\/zerojudge.tw\/ShowProblem?problemid=b179\">http:\/\/zerojudge.tw\/ShowProblem?problemid=b179<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: &#8230; \u7ed9\u5b9a\u4e00\u4e2a\u521d\u59cb\u57fa\u56e0\uff0c\u57fa\u56e0\u6bcf\u8f6e\u6bcf\u6b21\u4f1a\u5728\u540e\u9762\u6dfb\u52a0 {a, b, c ,d} \u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u5f62\u6210 4 \u4e2a\u65b0\u57fa\u56e0\u3002\u65e7\u57fa\u56e0\u5728\u5206\u88c2\u8fc7\u540e\u4f1a\u635f\u5931\u7b2c\u4e00\u4e2a\u5b57\u7b26\u3002\u3002\u3002\u3002 \u6709 n \u7ec4\u6709\u5bb3\u57fa\u56e0\uff0c\u5982\u679c\u51fa\u73b0\u4e86\u6709\u5bb3\u57fa\u56e0\u4f5c\u4e3a\u5b50\u4e32\u5219\u4e22\u5165\u533b\u9662\u3002\u3002 \u5982\u679c\u4e00\u4e2a\u57fa\u56e0\u957f\u5ea6\u53d8\u4e3a 0 \u5219\u88ab\u4e22\u5165\u56de\u6536\u573a\u3002\u3002 \u95ee\u6700\u540e\u5206\u522b\u6709\u591a\u5c11\u57fa\u56e0\u4e22\u5165\u533b\u9662\u591a\u5c11\u57fa\u56e0\u4e22\u5165\u56de\u6536\u573a\u3002\u3002\u3002 ( .. p<\/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":[16],"tags":[],"class_list":["post-279","post","type-post","status-publish","format-standard","hentry","category-online-judge"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-4v","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/279","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=279"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/279\/revisions"}],"predecessor-version":[{"id":280,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/279\/revisions\/280"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}