{"id":2875,"date":"2023-05-23T22:42:44","date_gmt":"2023-05-23T14:42:44","guid":{"rendered":"https:\/\/www.shuizilong.com\/house\/?p=2875"},"modified":"2023-05-23T22:42:44","modified_gmt":"2023-05-23T14:42:44","slug":"luogu-p4708-%e7%94%bb%e7%94%bb","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/luogu-p4708-%e7%94%bb%e7%94%bb\/","title":{"rendered":"Luogu P4708. \u753b\u753b"},"content":{"rendered":"<h2>\u9898\u610f<\/h2>\n<p>\u65e0\u6807\u53f7\u6b27\u62c9\u56fe\u8ba1\u6570<\/p>\n<h2>\u5206\u6790<\/h2>\n<p>\u505a\u6cd5\u57fa\u672c\u548c <a href=\"https:\/\/www.shuizilong.com\/house\/archives\/sgu-282-isomorphism\/\">SGU 282. Isomorphism<\/a> \u4e00\u6837\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#include &lt;lastweapon\/number&gt;\r\n\r\nusing namespace lastweapon;\r\n\r\nconst int N = int(5e1) + 9;\r\nInt Fact&#x5B;N]; VVI Partition; VI cur;\r\nint n;\r\n\r\nvoid gen(int n = ::n, int s = 1){\r\n    if (!n){\r\n        Partition.PB(cur);\r\n    }\r\n    else if (n &gt;= s){\r\n        cur.PB(s); gen(n-s, s); cur.pop_back();\r\n        gen(n, s+1);\r\n    }\r\n}\r\n\r\nInt c(const VI P){\r\n\r\n    Int z = Fact&#x5B;n]; int c = 0, l = P.front();\r\n\r\n    ECH(it, P){\r\n        z \/= *it; if (*it != l){\r\n            z \/= Fact&#x5B;c]; l = *it;\r\n            c = 1;\r\n        }\r\n        else{\r\n            ++c;\r\n        }\r\n    }\r\n\r\n    z \/= Fact&#x5B;c];\r\n    return z;\r\n}\r\n\r\nVII adj&#x5B;N];\r\nint w&#x5B;N]; bool vis&#x5B;N];\r\nint sw, sz;\r\n\r\nvoid dfs(int u) {\r\n    vis&#x5B;u] = 1;\r\n    sw += w&#x5B;u]; sz += 1;\r\n    for (auto e: adj&#x5B;u]) {\r\n        int v = e.fi; \/\/w = e.se;\r\n        if (!vis&#x5B;v]) dfs(v);\r\n    }\r\n}\r\n\r\nint g(const VI P){\r\n\r\n    REP(i, SZ(P)) {\r\n        w&#x5B;i] = 0; vis&#x5B;i] = 0;\r\n        adj&#x5B;i].clear();\r\n    }\r\n\r\n    int z = 0; REP(i, SZ(P)){\r\n        z += (P&#x5B;i] - 1) \/ 2;\r\n        if (!(P&#x5B;i]&amp;1)) w&#x5B;i] += 1;\r\n\r\n        REP(j, i) {\r\n            int d = __gcd(P&#x5B;i], P&#x5B;j]);\r\n            int ei = P&#x5B;j] \/ d, ej = P&#x5B;i] \/ d;\r\n            if (ei&amp;1) {\r\n                if (ej&amp;1) {\r\n                    adj&#x5B;i].PB({j,0});\r\n                    adj&#x5B;j].PB({i,0});\r\n                    z += d;\r\n                } else {\r\n                    w&#x5B;i] += d;\r\n                }\r\n            } else {\r\n                if (ej&amp;1) {\r\n                    w&#x5B;j] += d;\r\n                } else {\r\n                    z += d;\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    REP(i, SZ(P)) if (!vis&#x5B;i]){\r\n        sw = 0; sz = 0; dfs(i);\r\n        z += max(sw-1, 0) - (sz-1);\r\n    }\r\n    return z;\r\n}\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;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    MOD = 998244353;\r\n\r\n    RD(n); Fact&#x5B;0] = 1; REP_1(i, n) Fact&#x5B;i] = Fact&#x5B;i-1] * i;\r\n\r\n    gen();\r\n\r\n    Int res = 0; ECH(it, Partition){\r\n        res += c(*it) * pow(Int(2), g(*it));\r\n    }\r\n    res \/= Fact&#x5B;n];\r\n    cout &lt;&lt; res &lt;&lt; endl;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u610f \u65e0\u6807\u53f7\u6b27\u62c9\u56fe\u8ba1\u6570 \u5206\u6790 \u505a\u6cd5\u57fa\u672c\u548c SGU 282. Isomorphism \u4e00\u6837\u3002 #include &lt;lastweapon\/number&gt; using namespace lastweapon; const int N = int(5e1) + 9; Int Fact&#x5B;N]; VVI Partition; VI cur; int n; void gen(int n = ::n, int s = 1){ if (!n){ Partition.PB(cur); } else if (n &gt;= s){ cur.PB(s); gen(n-s, s); cur.pop_back(); gen(n, s+1); } } Int [&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-2875","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-Kn","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/2875","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=2875"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/2875\/revisions"}],"predecessor-version":[{"id":2876,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/2875\/revisions\/2876"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=2875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=2875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=2875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}