{"id":389,"date":"2017-03-17T16:19:17","date_gmt":"2017-03-17T08:19:17","guid":{"rendered":"http:\/\/kylelv.com\/?p=389"},"modified":"2017-12-28T14:54:06","modified_gmt":"2017-12-28T06:54:06","slug":"bzoj-1211-hnoi2004%e6%a0%91%e7%9a%84%e8%ae%a1%e6%95%b0-purfer%e5%ba%8f%e5%88%97","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=389","title":{"rendered":"bzoj 1211: [HNOI2004]\u6811\u7684\u8ba1\u6570  &#8212; purfer\u5e8f\u5217"},"content":{"rendered":"<p>&nbsp;<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fdefb17bb03\" 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-69fdefb17bb03\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.kylelv.com\/?p=389\/#1211_HNOI2004%E6%A0%91%E7%9A%84%E8%AE%A1%E6%95%B0\" title=\"1211: [HNOI2004]\u6811\u7684\u8ba1\u6570\">1211: [HNOI2004]\u6811\u7684\u8ba1\u6570<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=389\/#Description\" title=\"Description\">Description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=389\/#Input\" title=\"Input\">Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=389\/#Output\" title=\"Output\">Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=389\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=389\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=389\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"1211_HNOI2004%E6%A0%91%E7%9A%84%E8%AE%A1%E6%95%B0\"><\/span>1211: [HNOI2004]\u6811\u7684\u8ba1\u6570<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a010 Sec\u00a0\u00a0Memory Limit:\u00a0162 MB<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u4e00\u4e2a\u6709n\u4e2a\u7ed3\u70b9\u7684\u6811\uff0c\u8bbe\u5b83\u7684\u7ed3\u70b9\u5206\u522b\u4e3av1, v2, \u2026, vn\uff0c\u5df2\u77e5\u7b2ci\u4e2a\u7ed3\u70b9vi\u7684\u5ea6\u6570\u4e3adi\uff0c\u95ee\u6ee1\u8db3\u8fd9\u6837\u7684\u6761\u4ef6\u7684\u4e0d\u540c\u7684\u6811\u6709\u591a\u5c11\u68f5\u3002\u7ed9\u5b9an\uff0cd1, d2, \u2026, dn\uff0c\u7f16\u7a0b\u9700\u8981\u8f93\u51fa\u6ee1\u8db3d(vi)=di\u7684\u6811\u7684\u4e2a\u6570\u3002<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u7b2c\u4e00\u884c\u662f\u4e00\u4e2a\u6b63\u6574\u6570n\uff0c\u8868\u793a\u6811\u6709n\u4e2a\u7ed3\u70b9\u3002\u7b2c\u4e8c\u884c\u6709n\u4e2a\u6570\uff0c\u7b2ci\u4e2a\u6570\u8868\u793adi\uff0c\u5373\u6811\u7684\u7b2ci\u4e2a\u7ed3\u70b9\u7684\u5ea6\u6570\u3002\u5176\u4e2d1&lt;=n&lt;=150\uff0c\u8f93\u5165\u6570\u636e\u4fdd\u8bc1\u6ee1\u8db3\u6761\u4ef6\u7684\u6811\u4e0d\u8d85\u8fc710^17\u4e2a\u3002<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u8f93\u51fa\u6ee1\u8db3\u6761\u4ef6\u7684\u6811\u6709\u591a\u5c11\u68f5\u3002<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">4<br \/>\n2 1 2 1<br \/>\n<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">2<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6bcf\u4e00\u68f5\u6811\u90fd\u5bf9\u5e94\u7740\u552f\u4e00\u7684prufer\u6570\u5217\uff0cprufer\u6570\u5217\u4e5f\u5bf9\u5e94\u552f\u4e00\u7684\u6811\u3002prufer\u6570\u5217\u6784\u9020\u65b9\u6cd5\uff1a\u9009\u53d6\u7f16\u53f7\u6700\u5c0f\u7684\u53f6\u5b50\u8282\u70b9\u5220\u6389\uff0c\u5e76\u5c06\u5b83\u7684\u7236\u4eb2\u52a0\u5165\u5230prufer\u6570\u5217\u4e2d\uff0c\u76f4\u5230\u6811\u4e0a\u8fd8\u6709\u4e24\u4e2a\u8282\u70b9\u3002\u5047\u8bbe\u4e00\u4e2a\u70b9\u5165\u5ea6\u4e3ad\uff0c\u5b83\u6700\u591a\u6709\u53ef\u80fd\u5728prufer\u4e0a\u51fa\u73b0(d-1)\u6b21\uff08\u666e\u901a\u8282\u70b9\u4e0d\u53ef\u80fd\u56e0\u4e3a\u7236\u4eb2\u51fa\u73b0\u5728prufer\u4e0a\uff0c\u6839\u8282\u70b9\u7531\u4e8eprufer\u6784\u9020\u65f6\u8981\u7559\u4e24\u4e2a\u70b9\u6240\u4ee5\u4e5f\u4f1a\u6709\u4e00\u4e2a\u513f\u5b50\u65e0\u6cd5\u4f7f\u5b83\u51fa\u73b0\u5728prufer\u4e0a) \u00a0\uff0c\u6240\u4ee5\u4e00\u5171\u6709n-2\u4e2a\u6570\u5b57\u51fa\u73b0\u5728prufer\u4e0a\uff0c\u5176\u4e2d\u6bcf\u4e2a\u76f8\u540c\u6570\u5b57\u51fa\u73b0d-1\u6b21\uff0c\u6240\u4ee5\u7b54\u6848\u4e3a<\/p>\n<p>(n &#8211; 2) ! \/ ( (d1 &#8211; 1)! (d2 &#8211; 1)! \u2026\u2026(dn &#8211; 1)! )<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;cstdio&gt;\r\n#define ll long long\r\nll ans=1;\r\nint c[460],a[460],tot,n;\r\nvoid add(int x,int v)\r\n{\r\n    for(int k=2;k&lt;=x;k++)\r\n    while(x%k==0&amp;&amp;x&gt;0){a[k]+=v;x\/=k;}\r\n}\r\nll ksm(ll a,int b)\r\n{\r\n    ll sum=1;\r\n    for(;b;b&gt;&gt;=1){if(b&amp;1)sum*=a;a*=a;}\r\n    return sum;\r\n}\r\nint main()\r\n{\r\n    scanf(\"%d\",&amp;n);\r\n    for(int i=1;i&lt;=n;i++)\r\n    {\r\n        scanf(\"%d\",&amp;c[i]);\r\n        tot+=c[i];\r\n        if(c[i]==0&amp;&amp;n&gt;1){puts(\"0\");return 0;}\r\n    }\r\n    if(tot!=(n-1)*2){puts(\"0\");return 0;}\r\n    if(n==1){puts(\"1\");return 0;}\r\n    for(int i=2;i&lt;=n-2;i++) add(i,1);\r\n    for(int i=1;i&lt;=n;i++)\r\n        for(int j=2;j&lt;=c[i]-1;j++) add(j,-1);\r\n    for(int i=1;i&lt;=n;i++) ans*=ksm((ll)i,a[i]);\r\n    printf(\"%lld\\n\",ans);\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1211: [HNOI2004]\u6811\u7684\u8ba1\u6570 Time Limit:\u00a010 Sec\u00a0\u00a0Memory  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[24],"class_list":["post-389","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-prufer"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=389"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions"}],"predecessor-version":[{"id":391,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions\/391"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}