{"id":1198,"date":"2015-08-19T11:19:25","date_gmt":"2015-08-19T03:19:25","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=1198"},"modified":"2015-08-24T11:29:45","modified_gmt":"2015-08-24T03:29:45","slug":"2015-multi-university-training-contest-9-%ef%bc%8d-host-by-xudyh","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/2015-multi-university-training-contest-9-%ef%bc%8d-host-by-xudyh\/","title":{"rendered":"2015 Multi-University Training Contest 9 \uff0d Host by xudyh"},"content":{"rendered":"<p><!--more--><\/p>\n<h2>1001<\/h2>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;cstring&gt;\r\nusing namespace std;\r\n\r\n#define DO(n) for ( int ____n = n; ____n--&gt;0; )\r\n#define REP(i, n) for (int i=0;i&lt;n;++i)\r\n#define FOR(i, a, b) for (int i=a;i&lt;b;++i)\r\n#define DWN(i, b, a) for (int i=b-1;i&gt;=a;--i)\r\n#define REP_1(i, n) for (int i=1;i&lt;=n;++i)\r\n#define FOR_1(i, a, b) for (int i=a;i&lt;=b;++i)\r\n#define DWN_1(i, b, a) for (int i=b;i&gt;=a;--i)\r\n#define RST(A) memset(A, 0, sizeof(A))\r\n\r\n\r\ntypedef long long LL;\r\nconst int MOD = int(1e9) + 7;\r\n\r\nstruct Int{\r\n    int val;\r\n    \r\n    operator int() const{return val;}\r\n    \r\n    Int(int t){\r\n        val = t;\r\n    }\r\n    Int&amp; operator -=(const int&amp; rhs){\r\n        val -= rhs; if (val &lt; 0) val += MOD;\r\n        return *this;\r\n    }\r\n    Int&amp; operator +=(const int&amp; rhs){\r\n        val += rhs; if (val &gt;= MOD) val -= MOD;\r\n        return *this;\r\n    }\r\n    Int operator *(const int&amp; rhs) const{\r\n        LL z = (LL) val * rhs % MOD;\r\n        return z;\r\n    }\r\n};\r\n\r\n\r\nconst int N = int(1e2) + 9;\r\n\r\nint a&#x5B;N]; char op&#x5B;N];\r\nint Fact&#x5B;N], Binom&#x5B;N]&#x5B;N], dp&#x5B;N]&#x5B;N];\r\nint n;\r\n\r\nint w(int l, int r){\r\n    return Fact&#x5B;r-l];\r\n}\r\nint c(int l, int k, int r){\r\n    return Binom&#x5B;r-l-1]&#x5B;k-l];\r\n}\r\n\r\nInt f(int l, int r){\r\n    int &amp;z = dp&#x5B;l]&#x5B;r]; if (z == -1){\r\n        Int zz = 0; FOR(k, l, r) if (op&#x5B;k] == '*'){\r\n            zz += (Int) f(l, k) * f(k+1, r) * c(l, k, r);\r\n        }\r\n        else if (op&#x5B;k] == '+'){\r\n            zz += (Int) f(l, k) * w(k+1, r) * c(l, k, r);\r\n            zz += (Int) w(l, k) * f(k+1, r) * c(l, k, r);\r\n        }\r\n        else{\r\n            zz += (Int) f(l, k) * w(k+1, r) * c(l, k, r);\r\n            zz -= (Int) w(l, k) * f(k+1, r) * c(l, k, r);\r\n        }\r\n        z = zz % MOD;\r\n        if (z &lt; 0) z += MOD;\r\n    }\r\n    return z;\r\n}\r\n\r\n\/\/(3+5+7) + (2+4+7)\r\n\r\nint main(){\r\n    \r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;\/users\/xiaodao\/desktop\/Exercise\/in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;\/users\/xiaodao\/desktop\/Exercise\/out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n    \r\n    Fact&#x5B;0] = 1; FOR(i, 1, N) Fact&#x5B;i] = Int(Fact&#x5B;i-1]) * i;\r\n    \r\n    REP(i, N){\r\n        Binom&#x5B;i]&#x5B;0] = 1;\r\n        REP_1(j, i) Binom&#x5B;i]&#x5B;j] = (Binom&#x5B;i-1]&#x5B;j-1] + Binom&#x5B;i-1]&#x5B;j]) % MOD;\r\n    }\r\n    \r\n    \r\n    while (~scanf(&quot;%d&quot;, &amp;n)){\r\n        REP(i, n) scanf(&quot;%d&quot;, &amp;a&#x5B;i]); scanf(&quot;%s&quot;, op); memset(dp, -1, sizeof(dp));\r\n        REP(i, n) dp&#x5B;i]&#x5B;i] = a&#x5B;i];\r\n        printf(&quot;%d\\n&quot;, f(0, n-1));\r\n    }\r\n}\r\n\r\n\r\n\r\n\r\n<\/pre>\n<h2>1004<\/h2>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;cstring&gt;\r\nusing namespace std;\r\n\r\n#define DO(n) for ( int ____n = n; ____n--&gt;0; )\r\n#define REP(i, n) for (int i=0;i&lt;n;++i)\r\n#define FOR(i, a, b) for (int i=a;i&lt;b;++i)\r\n#define DWN(i, a, b) for (int i=a-1;i&gt;=b;--i)\r\n#define RST(A) memset(A, 0, sizeof(A))\r\n\r\ntypedef long long LL;\r\nconst int MOD = int(1e9) + 7;\r\n\r\nint pow(int a, int b){\r\n    int z = 1;\r\n    while (b){\r\n        if (b&amp;1) z = (LL)z * a % MOD;\r\n        a = (LL)a * a % MOD; b &gt;&gt;= 1;\r\n    }\r\n    return z;\r\n}\r\n\r\nconst int N = int(1e2) + 9;\r\nint Fact&#x5B;N], P&#x5B;N]&#x5B;N], I&#x5B;N], II&#x5B;N]; bool vis&#x5B;N];\r\nint n, m;\r\n\r\nint solve(){\r\n    bool bad = false; int d = 0; REP(i, m){\r\n        scanf(&quot;%d&quot;, &amp;P&#x5B;i]&#x5B;0]);\r\n        if (P&#x5B;i]&#x5B;0] == -1) ++d;\r\n        else{\r\n            RST(vis); vis&#x5B;P&#x5B;i]&#x5B;0]] = true;\r\n            FOR(j, 1, n){\r\n                scanf(&quot;%d&quot;, &amp;P&#x5B;i]&#x5B;j]);\r\n                if (vis&#x5B;P&#x5B;i]&#x5B;j]]) bad = true;\r\n                vis&#x5B;P&#x5B;i]&#x5B;j]] = true;\r\n            }\r\n        }\r\n    }\r\n    \r\n    if (bad) return 0;\r\n    \r\n    if (d){\r\n        return pow(Fact&#x5B;n], d-1);\r\n    }\r\n    else{\r\n        REP(i, n) I&#x5B;i] = i; DWN(i, m, 0){\r\n            REP(j, n) II&#x5B;j] = I&#x5B;j];\r\n            REP(j, n) I&#x5B;j] = P&#x5B;i]&#x5B;II&#x5B;j]] - 1;\r\n        }\r\n        \r\n        REP(i, n) if (I&#x5B;i] != i) return 0;\r\n        return 1;\r\n    }\r\n}\r\n\r\n\r\nint main(){\r\n    \r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;\/users\/xiaodao\/desktop\/Exercise\/in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;\/users\/xiaodao\/desktop\/Exercise\/out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n    \r\n    Fact&#x5B;0] = 1; FOR(i, 1, N) Fact&#x5B;i] = (LL) Fact&#x5B;i-1] * i % MOD;\r\n    while (cin &gt;&gt; n &gt;&gt; m){\r\n        cout &lt;&lt; solve() &lt;&lt; endl;\r\n    }\r\n}\r\n<\/pre>\n<h2>1005<\/h2>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;cstring&gt;\r\nusing namespace std;\r\n\r\n#define DO(n) for ( int ____n = n; ____n--&gt;0; )\r\n#define REP(i, n) for (int i=0;i&lt;n;++i)\r\n#define FOR(i, a, b) for (int i=a;i&lt;b;++i)\r\n#define DWN(i, b, a) for (int i=b-1;i&gt;=a;--i)\r\n#define REP_1(i, n) for (int i=1;i&lt;=n;++i)\r\n#define FOR_1(i, a, b) for (int i=a;i&lt;=b;++i)\r\n#define DWN_1(i, b, a) for (int i=b;i&gt;=a;--i)\r\n#define RST(A) memset(A, 0, sizeof(A))\r\n\r\ntypedef long long LL;\r\n\r\nconst int N = int(1e5) + 9;\r\nint A&#x5B;N], L&#x5B;N], R&#x5B;N], n, d1, d2;\r\n\r\n\r\nLL solve(){\r\n    LL z = 0;\r\n    \r\n    REP(i, n) scanf(&quot;%d&quot;, &amp;A&#x5B;i]);\r\n    \r\n    REP(i, n-1){\r\n        if (A&#x5B;i+1] - A&#x5B;i] == d1){\r\n            L&#x5B;i+1] = L&#x5B;i] + 1;\r\n        }\r\n        else{\r\n            L&#x5B;i+1] = 0;\r\n        }\r\n    }\r\n    \r\n    R&#x5B;n-1] = 0;\r\n    DWN(i, n-1, 0){\r\n        if (A&#x5B;i+1] - A&#x5B;i] == d2){\r\n            R&#x5B;i] = R&#x5B;i+1] + 1;\r\n        }\r\n        else{\r\n            R&#x5B;i] = 0;\r\n        }\r\n    }\r\n    \r\n    \r\n    \r\n    if (d1 == d2){\r\n        \/*REP(i, n){\r\n            z += (LL)(R&#x5B;i]+1)*(R&#x5B;i]+2) \/ 2;\r\n            i += R&#x5B;i];\r\n        }\r\n        return z;*\/\r\n        REP(i, n) L&#x5B;i] = 0;\r\n    }\r\n    \r\n    \r\n    REP(i, n){\r\n        z += (LL) (L&#x5B;i]+1)*(R&#x5B;i]+1);\r\n    }\r\n    return z;\r\n}\r\n\r\n\r\nint main(){\r\n    \r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;\/users\/xiaodao\/desktop\/Exercise\/in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;\/users\/xiaodao\/desktop\/Exercise\/out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n    \r\n    while (cin &gt;&gt; n &gt;&gt; d1 &gt;&gt; d2){\r\n        cout &lt;&lt; solve() &lt;&lt; endl;\r\n    }\r\n}\r\n<\/pre>\n<h2>1007<\/h2>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\nusing namespace std;\r\n\r\n#define DO(n) for ( int ____n = n; ____n--&gt;0; )\r\n#define REP(i, n) for (int i=0;i&lt;n;++i)\r\n\r\nconst int N = int(1e2) + 9;\r\nint A&#x5B;N]&#x5B;N];\r\nint n, m;\r\n\r\n\r\nconst int dx&#x5B;] = {1, 0, -1, 0};\r\nconst int dy&#x5B;] = {0, 1, 0, 1};\r\nconst char op&#x5B;] = {'D', 'R', 'U', 'R'};\r\nconst int SZ = 4;\r\n\r\nvoid snake(int x, int y, int tx, int ty){\r\n    int p = 0; bool flag = true; DO(2*(m-1) - 1){\r\n        if (x+dx&#x5B;p] == tx &amp;&amp; y+dy&#x5B;p] == ty){\r\n            flag = false; ++y;\r\n            putchar('R');\r\n        }\r\n        x += dx&#x5B;p]; y += dy&#x5B;p]; putchar(op&#x5B;p]);\r\n        ++p; if (p == SZ) p = 0;\r\n    }\r\n    if (flag) putchar('R');\r\n}\r\n\r\n\r\nint main() {\r\n    \r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;\/users\/xiaodao\/desktop\/Exercise\/in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;\/users\/xiaodao\/desktop\/Exercise\/out.txt&quot;, &quot;w&quot;, stdout);\r\n    \r\n#endif\r\n    \r\n    while (cin &gt;&gt; n &gt;&gt; m){\r\n        \r\n        int z = 0; REP(i, n) REP(j, m){\r\n            scanf(&quot;%d&quot;, &amp;A&#x5B;i]&#x5B;j]);\r\n            z += A&#x5B;i]&#x5B;j];\r\n        }\r\n            \r\n        if (n&amp;1){\r\n            cout &lt;&lt; z &lt;&lt; endl;\r\n            REP(i, n){\r\n                DO(m-1) putchar( (i&amp;1) ? 'L' : 'R');\r\n                if (i != n-1) putchar('D');\r\n            }\r\n        }\r\n        else if (m&amp;1){\r\n            cout &lt;&lt; z &lt;&lt; endl;\r\n            REP(i, m){\r\n                DO(n-1) putchar( (i&amp;1) ? 'U' : 'D');\r\n                if (i != m-1) putchar('R');\r\n            }\r\n        }\r\n        else{\r\n            int x = 0, y = 1;\r\n            REP(i, n) REP(j, m) if ((i+j)&amp;1){\r\n                if (A&#x5B;i]&#x5B;j] &lt; A&#x5B;x]&#x5B;y]){\r\n                    x = i, y = j;\r\n                }\r\n            }\r\n            z -= A&#x5B;x]&#x5B;y];\r\n            cout &lt;&lt; z &lt;&lt; endl;\r\n\r\n            bool flag = true;\r\n            REP(i, n\/2){\r\n                \r\n                if (i) putchar('D');\r\n                \r\n                if (flag){\r\n                    \r\n                    if (x\/2 == i){\r\n                        snake(i*2, 0, x, y);\r\n                        flag = false;\r\n                        continue;\r\n                    }\r\n                    \r\n                    DO(m-1) putchar('R'); putchar('D');\r\n                    DO(m-1) putchar('L');\r\n                }\r\n                else{\r\n                    DO(m-1) putchar('L'); putchar('D');\r\n                    DO(m-1) putchar('R');\r\n                }\r\n                \r\n            }\r\n        }\r\n        \r\n        puts(&quot;&quot;);\r\n    }   \r\n}\r\n<\/pre>\n<pre>\n4 2\n1 1\n1 1\n1 1\n1 1\n\n2 4\n1 1 1 1\n1 1 1 1\n<\/pre>\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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[104],"tags":[],"class_list":["post-1198","post","type-post","status-publish","format-standard","hentry","category-multi-university-training"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-jk","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1198","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=1198"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1198\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}