{"id":2143,"date":"2023-01-17T00:19:40","date_gmt":"2023-01-16T16:19:40","guid":{"rendered":"https:\/\/www.shuizilong.com\/house\/?p=2143"},"modified":"2023-01-17T18:10:11","modified_gmt":"2023-01-17T10:10:11","slug":"codeforces-round-844","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-844\/","title":{"rendered":"Codeforces Round #844"},"content":{"rendered":"<p>\u53c8\u662f\u4e45\u8fdd\u7684 tourist round\u3002\u3002\u3002<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_65 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f1a1f103a22\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f1a1f103a22\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-844\/#Problem_D\" title=\"Problem D.\">Problem D.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-844\/#Problem_F_%E2%80%93_Bracket_Insertion\" title=\"Problem F &#8211; Bracket Insertion\">Problem F &#8211; Bracket Insertion<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-844\/#%E9%A2%98%E6%84%8F\" title=\"\u9898\u610f\">\u9898\u610f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-844\/#%E9%A2%98%E8%A7%A3\" title=\"\u9898\u89e3\">\u9898\u89e3<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<h1><span class=\"ez-toc-section\" id=\"Problem_D\"><\/span>Problem D.<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/599333683\">https:\/\/zhuanlan.zhihu.com\/p\/599333683<\/a><\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"Problem_F_%E2%80%93_Bracket_Insertion\"><\/span>Problem F &#8211; Bracket Insertion<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"%E9%A2%98%E6%84%8F\"><\/span>\u9898\u610f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6784\u9020\u4e00\u4e2a\u521d\u59cb\u4e3a\u7a7a\u7684\u62ec\u53f7\u5e8f\u5217\uff0c\u6267\u884c n \u6b21\u63d2\u5165\u64cd\u4f5c\uff0c\u6bcf\u6b21\u64cd\u4f5c\u4efb\u9009\u5e8f\u5217\u4e2d\u7684\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u63d2\u5165 <code>\"()\"<\/code> \u6216 <code>\")(\"<\/code>\u3002<br \/>\n\u95ee\u6700\u7ec8\u6784\u6210\u7684\u62ec\u53f7\u5e8f\u5217\u4e3a\u5408\u6cd5\u62ec\u53f7\u5e8f\u5217\u7684\u64cd\u4f5c\u65b9\u6848\u7684\u6982\u7387\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E9%A2%98%E8%A7%A3\"><\/span>\u9898\u89e3<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u7ec4\u5408\u8ba1\u6570\u3002<br \/>\n\u5148\u8f6c\u6362\u6210\u8ba1\u6570\u95ee\u9898\uff0c\u4e0d\u96be\u53d1\u73b0\uff0c\u5bf9\u4e8e\u7b2c i \u6b21\u64cd\u4f5c\uff0c\u6211\u4eec\u6709 <code>i*2-1<\/code> \u79cd\u63d2\u5165\u7684\u4f4d\u7f6e\u53ef\u4f9b\u9009\u62e9\uff0c\u56e0\u800c\u6c42\u51fa\u5408\u6cd5\u7684\u64cd\u4f5c\u65b9\u6848\u603b\u6570\uff0c\u5904\u4ee5 <code>1*3*5*...*2n-1<\/code> \u5373\u53ef\u3002<br \/>\n\u9ebb\u70e6\u7684\u662f\uff0c\u6211\u4eec\u751a\u81f3\u4e0d\u80fd\u628a\u6bcf\u6b21\u63d2\u5165\u7684\u4e00\u5bf9\u62ec\u53f7\u770b\u6210\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u5143\u7d20\uff0c\u540e\u7eed\u63d2\u5165\u64cd\u4f5c\u751a\u81f3\u53ef\u4ee5\u4ece\u4e2d\u95f4\u7834\u574f\u5b83\u3002<\/p>\n<p>\u56de\u5fc6 Catalan \u5e8f\u5217\u7684\u505a\u6cd5\uff0c\u867d\u7136\u548c\u8fd9\u4e2a\u9898\u770b\u8d77\u6765\u6709\u5f88\u5927\u7684\u4e0d\u540c\uff0c\u524d\u8005\u662f\u8ba1\u6570\u5408\u6cd5\u7684\u62ec\u53f7\u5e8f\u5217\u603b\u6570\uff0c\u672c\u9898\u662f\u8ba1\u6570\u5408\u6cd5\u7684\u64cd\u4f5c\u65b9\u6848\u3002<br \/>\n\u4f46\u662f\u4f9d\u7136\u53ef\u4ee5\u7ed9\u6211\u4eec\u63d0\u4f9b\u8bb8\u591a\u6709\u76ca\u7684\u601d\u8def\u3002\u56de\u5fc6 Catalan \u5e8f\u5217\u7684\u5377\u79ef\u5f62\u9012\u63a8\u516c\u5f0f\u3002<br \/>\n\u6211\u4eec\u5b9e\u9645\u4e0a\u662f\u8003\u5bdf\u7b2c\u4e00\u7ec4\u5339\u914d\u7684\u62ec\u53f7\uff0c\u7136\u540e\u5206\u522b\u679a\u4e3e\u62ec\u53f7\u5185\u6216\u62ec\u53f7\u5916\u7684\u62ec\u53f7\u5c42\u6570\uff0c\u4ee5\u8fdb\u884c\u9012\u5f52\u3002<\/p>\n<p>\u8fd9\u4e2a\u9898\u662f\u5426\u53ef\u4ee5\u4f7f\u7528\u540c\u6837\u7684\u7b56\u7565\u5462\uff1f<br \/>\n\u6211\u4eec\u540c\u6837\u56fa\u5b9a\u7b2c\u4e00\u7ec4\u62ec\u53f7\uff0c\u90a3\u4e48\u4e4b\u540e\u7684\u62ec\u53f7\uff0c\u53ea\u4f1a\u662f\u4e0b\u8ff0\u4e09\u79cd\u60c5\u51b5\u4e4b\u4e00\uff1aL(M)R\u3002<br \/>\n\u56e0\u4e3a\u88ab\u521d\u59cb\u62ec\u53f7\u6240\u5206\u5272\uff0c\u8fd9\u91cc L M R \u7684\u72b6\u6001\u90fd\u72ec\u7acb\u7684\u3002<br \/>\n\u8fd9\u91cc L \u548c R \u7684 size \u53ef\u4ee5\u5408\u5e76\u5728\u4e00\u8d77\uff0c\u8fd9\u6837\u6211\u4eec\u53ea\u8981\u679a\u4e3e M \u7684 size \u5373\u53ef\u3002<\/p>\n<p>\u8fd9\u6837\u6211\u4eec\u5c31\u6709\u4e86\u7c7b Catalan \u7684\u9012\u63a8\u5173\u7cfb\uff0c\u8fdb\u4e00\u6b65\u8fd9\u91cc\u7684\u4e0d\u540c\u65f6\uff0c\u5b50\u72b6\u6001\u4e2d\u5e76\u4e0d\u4e00\u5b9a\u8981\u6c42\u662f\u5408\u6cd5\u7684\u62ec\u53f7\u5e8f\u5217\uff0c<br \/>\n\u6211\u4eec\u9700\u8981\u8bb0\u5f55\u5b50\u72b6\u6001\u7684\u4e0d\u5408\u6cd5\u7684\u7b49\u7ea7\uff0c\u4e5f\u5c31\u662f\u524d\u7f00\u548c\u7684\u6700\u5c0f\u503c\u3002<\/p>\n<p>\u8fdb\u4e00\u6b65\u8003\u8651\u7ec6\u8282\uff0c\u5728\u8f6c\u79fb\u65f6\uff0c\u6211\u4eec\u53d1\u73b0\u6211\u4eec\u53ea\u9700\u8981\u8003\u8651\u524d\u7f00\u548c >= j \u7684\u72b6\u6001\uff0c\u56e0\u6b64\u53ef\u4ee5\u76f4\u63a5\u5c06\u524d\u7f00\u548c\u5b9a\u4e49\u5728\u72b6\u6001\u4e2d\u3002<br \/>\nf[i][j]: \u6267\u884c\u4e86 i \u6b21\u63d2\u5165\u64cd\u4f5c\uff0c\u4e14\u5f53\u524d\u524d\u7f00\u548c\u6700\u5c0f\u503c\u4e0d\u5c0f\u4e8e -j \u7684\u65b9\u6848\u6570\u3002<br \/>\n\u6211\u4eec\u679a\u4e3e\u5de6\u53f3\u7684\u5b50\u6811 size \u548c a \u6216\u4e2d\u95f4\u7684\u5b50\u6811 size b\uff0c\u5f97\u5230\u8f6c\u79fb\u65b9\u7a0b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-e6b165c49de3442b78aa793ad933476d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#32;&#102;&#091;&#105;&#093;&#091;&#106;&#093;&#32;&#61;&#32;&#92;&#115;&#117;&#109;&#32;&#102;&#95;&#50;&#091;&#97;&#093;&#091;&#106;&#093;&#32;&#40;&#112;&#32;&#92;&#99;&#100;&#111;&#116;&#32;&#102;&#091;&#98;&#093;&#091;&#106;&#43;&#49;&#093;&#43;&#113;&#92;&#99;&#100;&#111;&#116;&#32;&#102;&#091;&#98;&#093;&#091;&#106;&#45;&#49;&#093;&#41;&#32;&#92;&#98;&#105;&#110;&#111;&#109;&#123;&#105;&#45;&#49;&#125;&#123;&#97;&#44;&#32;&#98;&#125;&#32;\" title=\"Rendered by QuickLaTeX.com\" height=\"26\" width=\"412\" style=\"vertical-align: -9px;\"\/><\/p>\n<p>\u8fd9\u91cc\u7684\u8f6c\u79fb\u51fa\u73b0\u4e86\u7ec4\u5408\u6570\uff0c\u4e00\u4e2a\u5e38\u89c1\u7684\u6280\u5de7\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u7c7b\u6bd4 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Generating_function#Exponential_generating_function_(EGF)\">EFG<\/a> \u4e2d\u7684\u5904\u7406\u65b9\u6cd5\uff0c\u5bf9\u6bcf\u4e2a\u72b6\u6001 f[i][j] \u90fd\u9664\u4ee5 i! \u4ee5\u7b80\u5316\u8f6c\u79fb\u3002\uff08\u7136\u540e\u4e0b\u6807\u91cc\u6709 -1 \u4e5f\u5f88\u70e6\uff0c\u4e0d\u5982\u4e5f offset \u4e00\u4e0b\u3002\u3002\u3002\uff09<\/p>\n<p><a href=\"https:\/\/codeforces.com\/contest\/1782\/submission\/189455837\">https:\/\/codeforces.com\/contest\/1782\/submission\/189455837<\/a><\/p>\n<pre class=\"brush: cpp; light: false; title: F1.cpp; toolbar: true; notranslate\" title=\"F1.cpp\">\r\n#include &lt;lastweapon\/number&gt;\r\nusing namespace lastweapon;\r\nconst int N = int(5e2) + 9;\r\nInt f&#x5B;N]&#x5B;N], f2&#x5B;N]&#x5B;N], I&#x5B;2*N], Fact&#x5B;2*N]; \/\/ i step, min pref sum &gt;= -(j-1)\r\nint n; Int p, q;\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;\/Users\/minakokojima\/Documents\/GitHub\/ACM-Training\/Workspace\/out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    MOD = 998244353;\r\n\tRD(n); p = Int(RD()) \/ 10000; q = Int(1) - p;\r\n\tfor (int i=(I&#x5B;1]=1)+1; i&lt;=2*n; i++) I&#x5B;i] = 1ll * (MOD - MOD \/ i) * I&#x5B;MOD%i] % MOD;\r\n\tFact&#x5B;0] = 1; REP_1(i, n) Fact&#x5B;i] = Fact&#x5B;i-1] * i;\r\n\r\n\tREP_1(i, n+1) f2&#x5B;0]&#x5B;i] = f&#x5B;0]&#x5B;i] = 1;\r\n\r\n\t\/\/ \\sum f&#x5B;a1] * f&#x5B;a2] * (p*f&#x5B;b]+q*f&#x5B;b]) * \\binom{i-1}{a, b}\r\n\tREP_1(i, n) REP_1(j, n-i+1) {\r\n        REP(a, i) {\r\n            int b = i-1-a;\r\n            f&#x5B;i]&#x5B;j] += f2&#x5B;a]&#x5B;j] * (p*f&#x5B;b]&#x5B;j+1] + q*f&#x5B;b]&#x5B;j-1]);\r\n        }\r\n        f&#x5B;i]&#x5B;j] *= I&#x5B;i];\r\n        REP(a, i+1) {\r\n            int b = i-a;\r\n            f2&#x5B;i]&#x5B;j] += f&#x5B;a]&#x5B;j] * f&#x5B;b]&#x5B;j];\r\n        }\r\n\t}\r\n\r\n    Int z = f&#x5B;n]&#x5B;1] * Fact&#x5B;n]; REP_1(i, n) {\r\n        z *= I&#x5B;i*2-1];\r\n    }\r\n    cout &lt;&lt; z &lt;&lt; endl;\r\n}\r\n<\/pre>\n<p>\u8fdb\u4e00\u6b65\uff0c\u548c Catalan \u5e8f\u5217\u4e00\u6837\uff0c\u8fd9\u4e2a\u9898\u4e5f\u53ef\u4ee5\u4ece\u6811\u7684\u89d2\u5ea6\u8fdb\u884c\u601d\u8003\u3002<br \/>\n\u6211\u4eec\u8bbe\u6cd5\u5efa\u7acb\u8d77\u62ec\u53f7\u5e8f\u5217\u4e0e\u4e00\u4e2a\u6709\u6807\u53f7\u68ee\u6797\u7684\u4e00\u4e00\u5bf9\u5e94\u5173\u7cfb\uff08\u68ee\u6797\u4e5f\u53ef\u89c6\u4e3a\u6709\u4e00\u4e2a\u865a\u6839\u8282\u70b9\u7684\u6811\uff09\uff0c<br \/>\n\u6bcf\u6b21\u64cd\u4f5c\uff0c\u6211\u4eec\u90fd\u76f8\u5f53\u4e8e\u6309\u7167\u987a\u5e8f\uff0c\u63d2\u5165\u4e00\u4e2a\u65b0\u7684\u6709\u6807\u53f7\u7684\u53f6\u5b50\u8282\u70b9\uff08\u533a\u5206\u5b69\u5b50\u7684\u987a\u5e8f\uff09\uff08\u7956\u5148\u7684\u6807\u53f7\u4e00\u5b9a\u5c0f\u4e8e\u5b69\u5b50\uff09\u3002<\/p>\n<p>\u62ec\u53f7\u7684\u72b6\u6001\u5bf9\u5e94\u8282\u70b9\u5904\u6743\u503c \uff081 \u6216 -1\uff09\uff0c\u62ec\u53f7\u5e8f\u5217\u7684\u524d\u7f00\u548c\u5bf9\u5e94\u6811\u4e2d\u7684\u4e00\u6bb5 <code>dfs<\/code> \u5e8f\uff0c\u4e5f\u5c31\u662f\u6839\u5230\u6bcf\u4e00\u4e2a\u8282\u70b9\u7684\u8def\u5f84\u7684\u6743\u503c\u548c\u3002<br \/>\n\u62ec\u53f7\u5e8f\u5217\u5408\u6cd5\uff0c\u5c31\u662f\u6240\u6709\u8fd9\u4e9b\u548c\u90fd <code>>= 0<\/code>\u3002<\/p>\n<p>\u540c\u6837\u7684\uff0c\u5728\u8f6c\u79fb\u8fc7\u7a0b\u4e2d\uff0c\u62ec\u53f7\u5e8f\u5217\u5141\u8bb8\u4e0d\u5408\u6cd5\uff0c\u6211\u4eec\u8fdb\u884c\u540c\u6837\u7684\u52a0\u7ef4\uff0c\u53ea\u662f\u8fd9\u91cc\u56e0\u4e3a\u6211\u4eec\u5df2\u7ecf\u5efa\u7acb\u4e86\u4e00\u4e00\u5bf9\u5e94\u5173\u7cfb\uff0c\u8f6c\u79fb\u65f6\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u5bf9\u8fd9\u91cc\u7684\u6811\u7ed3\u6784\u8fdb\u884c\u8ba1\u6570\u3002<br \/>\n\u6211\u4eec\u76f4\u63a5\u679a\u4e3e\u6811\u7684\u5f62\u6001\uff0c\u518d\u7528\u7ec4\u5408\u6570\u91cd\u65b0\u8fdb\u884c\u6807\u53f7\uff0c\u5f97\u5230\u66f4\u7b80\u5355\u7684\u8f6c\u79fb\u65b9\u7a0b\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-56c0ff0aec48c87baa78af10d4569a84_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#32;&#102;&#091;&#105;&#093;&#091;&#106;&#093;&#32;&#61;&#32;&#92;&#115;&#117;&#109;&#32;&#102;&#091;&#97;&#093;&#091;&#106;&#093;&#32;&#40;&#112;&#92;&#99;&#100;&#111;&#116;&#32;&#102;&#091;&#98;&#093;&#091;&#106;&#43;&#49;&#093;&#43;&#113;&#92;&#99;&#100;&#111;&#116;&#32;&#102;&#091;&#98;&#093;&#091;&#106;&#45;&#49;&#093;&#41;&#32;&#92;&#98;&#105;&#110;&#111;&#109;&#123;&#105;&#125;&#123;&#97;&#44;&#32;&#98;&#43;&#49;&#125;&#32;\" title=\"Rendered by QuickLaTeX.com\" height=\"26\" width=\"419\" style=\"vertical-align: -9px;\"\/><\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc\u7684 b+1 \u662f\u56e0\u4e3a\uff0c\u6211\u4eec\u5df2\u7ecf\u628a size \u4e3a b \u7684\u68ee\u6797\uff0c\u548c\u4e00\u4e2a\u65b0\u7684\u8282\u70b9\u4f5c\u4e3a\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u5b50\u6811\uff0c\u8fde\u63a5\u5728\u865a\u6839\u8282\u70b9\u4e0a\u3002<br \/>\n\u5f97\u5230\u7684\u65b9\u7a0b\u66f4\u4e3a\u7b80\u6d01\u3002<\/p>\n<p>\uff08\u5f53\u7136\u8fd9\u4e24\u79cd\u505a\u6cd5\u662f\u5b8c\u5168\u7b49\u4ef7\u7684\uff0c\u65e0\u8bba\u4ece\u62ec\u53f7\u5e8f\u5217\u7684\u89d2\u5ea6\u5206\u6790\u8fd8\u662f\u4ece\u6811\u7684\u89d2\u5ea6\u5206\u6790\uff0c\u53ea\u662f\u63cf\u8ff0\u7684\u8bed\u8a00\u7565\u6709\u4e0d\u540c\u7f62\u4e86\uff0c\u90fd\u80fd\u5f97\u5230\u4e24\u79cd\u8f6c\u79fb\u65b9\u7a0b\uff0c<br \/>\n\u533a\u522b\u662f\u6211\u4eec\u9012\u5f52\u7684\u65f6\u5019\u662f\u62ce\u51fa\u6765\u8003\u5bdf\u7684\u662f\u7f16\u53f7\u4e3a 1 \u7684\u8282\u70b9\u6240\u5728\u7684\u5b50\u6811\uff0c\u8fd8\u662f\u4f4d\u7f6e\u9760\u8fb9\u7684\u4e00\u4e2a\u5b50\u6811\u3002\uff09<\/p>\n<p><a href=\"https:\/\/codeforces.com\/contest\/1782\/submission\/189456196\">https:\/\/codeforces.com\/contest\/1782\/submission\/189456196<\/a><\/p>\n<pre class=\"brush: cpp; light: false; title: F2.cpp; toolbar: true; notranslate\" title=\"F2.cpp\">\r\n#include &lt;lastweapon\/number&gt;\r\nusing namespace lastweapon;\r\nconst int N = int(5e2) + 9;\r\nInt f&#x5B;N]&#x5B;N], I&#x5B;2*N], Fact&#x5B;2*N]; \/\/ i step, min pref sum &gt;= -(j-1)\r\nint n; Int p, q;\r\n\r\nint main() {\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;\/Users\/minakokojima\/Documents\/GitHub\/ACM-Training\/Workspace\/out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    MOD = 998244353;\r\n\tRD(n); p = Int(RD()) \/ 10000; q = Int(1) - p;\r\n\tfor (int i=(I&#x5B;1]=1)+1; i&lt;=2*n; i++) I&#x5B;i] = 1ll * (MOD - MOD \/ i) * I&#x5B;MOD%i] % MOD;\r\n\tFact&#x5B;0] = 1; REP_1(i, n) Fact&#x5B;i] = Fact&#x5B;i-1] * i;\r\n\r\n\tREP_1(i, n+1) f&#x5B;0]&#x5B;i] = 1;\r\n\r\n\t\/\/ \\sum f&#x5B;a] * (p*f&#x5B;b]+q*f&#x5B;b]) * \\binom{i}{a, b+1}\r\n\tREP_1(i, n) REP_1(j, n-i+1) {\r\n        REP(a, i) {\r\n            int b = i-1-a;\r\n            f&#x5B;i]&#x5B;j] += f&#x5B;a]&#x5B;j] * (p*f&#x5B;b]&#x5B;j+1] + q*f&#x5B;b]&#x5B;j-1]) * I&#x5B;b+1];\r\n        }\r\n\t}\r\n\r\n    Int z = f&#x5B;n]&#x5B;1] * Fact&#x5B;n]; REP_1(i, n) {\r\n        z *= I&#x5B;i*2-1];\r\n    }\r\n    cout &lt;&lt; z &lt;&lt; endl;\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53c8\u662f\u4e45\u8fdd\u7684 tourist round\u3002\u3002\u3002 Problem D. https:\/\/zhuanlan.zhihu.com\/p\/599333683 Problem F &#8211; Bracket Insertion \u9898\u610f \u6784\u9020\u4e00\u4e2a\u521d\u59cb\u4e3a\u7a7a\u7684\u62ec\u53f7\u5e8f\u5217\uff0c\u6267\u884c n \u6b21\u63d2\u5165\u64cd\u4f5c\uff0c\u6bcf\u6b21\u64cd\u4f5c\u4efb\u9009\u5e8f\u5217\u4e2d\u7684\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u63d2\u5165 &#8220;()&#8221; \u6216 &#8220;)(&#8220;\u3002 \u95ee\u6700\u7ec8\u6784\u6210\u7684\u62ec\u53f7\u5e8f\u5217\u4e3a\u5408\u6cd5\u62ec\u53f7\u5e8f\u5217\u7684\u64cd\u4f5c\u65b9\u6848\u7684\u6982\u7387\u3002 \u9898\u89e3 \u7ec4\u5408\u8ba1\u6570\u3002 \u5148\u8f6c\u6362\u6210\u8ba1\u6570\u95ee\u9898\uff0c\u4e0d\u96be\u53d1\u73b0\uff0c\u5bf9\u4e8e\u7b2c i \u6b21\u64cd\u4f5c\uff0c\u6211\u4eec\u6709 i*2-1 \u79cd\u63d2\u5165\u7684\u4f4d\u7f6e\u53ef\u4f9b\u9009\u62e9\uff0c\u56e0\u800c\u6c42\u51fa\u5408\u6cd5\u7684\u64cd\u4f5c\u65b9\u6848\u603b\u6570\uff0c\u5904\u4ee5 1*3*5*&#8230;*2n-1 \u5373\u53ef\u3002 \u9ebb\u70e6\u7684\u662f\uff0c\u6211\u4eec\u751a\u81f3\u4e0d\u80fd\u628a\u6bcf\u6b21\u63d2\u5165\u7684\u4e00\u5bf9\u62ec\u53f7\u770b\u6210\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u5143\u7d20\uff0c\u540e\u7eed\u63d2\u5165\u64cd\u4f5c\u751a\u81f3\u53ef\u4ee5\u4ece\u4e2d\u95f4\u7834\u574f\u5b83\u3002 \u56de\u5fc6 Catalan \u5e8f\u5217\u7684\u505a\u6cd5\uff0c\u867d\u7136\u548c\u8fd9\u4e2a\u9898\u770b\u8d77\u6765\u6709\u5f88\u5927\u7684\u4e0d\u540c\uff0c\u524d\u8005\u662f\u8ba1\u6570\u5408\u6cd5\u7684\u62ec\u53f7\u5e8f\u5217\u603b\u6570\uff0c\u672c\u9898\u662f\u8ba1\u6570\u5408\u6cd5\u7684\u64cd\u4f5c\u65b9\u6848\u3002 \u4f46\u662f\u4f9d\u7136\u53ef\u4ee5\u7ed9\u6211\u4eec\u63d0\u4f9b\u8bb8\u591a\u6709\u76ca\u7684\u601d\u8def\u3002\u56de\u5fc6 Catalan \u5e8f\u5217\u7684\u5377\u79ef\u5f62\u9012\u63a8\u516c\u5f0f\u3002 \u6211\u4eec\u5b9e\u9645\u4e0a\u662f\u8003\u5bdf\u7b2c\u4e00\u7ec4\u5339\u914d\u7684\u62ec\u53f7\uff0c\u7136\u540e\u5206\u522b\u679a\u4e3e\u62ec\u53f7\u5185\u6216\u62ec\u53f7\u5916\u7684\u62ec\u53f7\u5c42\u6570\uff0c\u4ee5\u8fdb\u884c\u9012\u5f52\u3002 \u8fd9\u4e2a\u9898\u662f\u5426\u53ef\u4ee5\u4f7f\u7528\u540c\u6837\u7684\u7b56\u7565\u5462\uff1f \u6211\u4eec\u540c\u6837\u56fa\u5b9a\u7b2c\u4e00\u7ec4\u62ec\u53f7\uff0c\u90a3\u4e48\u4e4b\u540e\u7684\u62ec\u53f7\uff0c\u53ea\u4f1a\u662f\u4e0b\u8ff0\u4e09\u79cd\u60c5\u51b5\u4e4b\u4e00\uff1aL(M)R\u3002 \u56e0\u4e3a\u88ab\u521d\u59cb\u62ec\u53f7\u6240\u5206\u5272\uff0c\u8fd9\u91cc L M R \u7684\u72b6\u6001\u90fd\u72ec\u7acb\u7684\u3002 \u8fd9\u91cc L \u548c R \u7684 size \u53ef\u4ee5\u5408\u5e76\u5728\u4e00\u8d77\uff0c\u8fd9\u6837\u6211\u4eec\u53ea\u8981\u679a\u4e3e M \u7684 size \u5373\u53ef\u3002 \u8fd9\u6837\u6211\u4eec\u5c31\u6709\u4e86\u7c7b [&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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-2143","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-yz","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/2143","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=2143"}],"version-history":[{"count":28,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/2143\/revisions"}],"predecessor-version":[{"id":2171,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/2143\/revisions\/2171"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=2143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=2143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=2143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}