题目链接

洛谷P4233

题解

我们只需求出总的哈密顿回路个数和总的强联通竞赛图个数

对于每条哈密顿回路,我们统计其贡献

一条哈密顿回路就是一个圆排列,有\(\frac{n!}{n}\)种,剩余边随便连

所以总的贡献为

\[(n - 1)!2^{{n \choose 2} - n}
\]

我们只需求出总的强联通竞赛图的个数

设\(g[n]\)表示\(n\)个点竞赛图个数,\(f[n]\)表示强联通竞赛图个数

那么有

\[g[n] = \sum\limits_{i = 1}^{n}{n \choose i}f[i]g[n - i]
\]

\[\frac{g[n]}{n!} = \sum\limits_{i = 1}^{n}\frac{f[i]}{i!}\frac{g[n - i]}{(n - i)!}
\]

设\(G(x)\)和\(F(x)\)分别为其指数型生成函数

那么有

\[G(x) = F(x)G(x) + 1
\]

\[F(x) = \frac{G(x) - 1}{G(x)}
\]

多项式求逆即可

复杂度\(O(nlogn)\)

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 400005,maxm = 100005,INF = 0x3f3f3f3f;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
return flag ? out : -out;
}
const int P = 998244353,G = 3;
inline int qpow(int a,LL b){
int re = 1;
for (; b; b >>= 1,a = 1ll * a * a % P)
if (b & 1) re = 1ll * re * a % P;
return re;
}
inline LL C(int n){return 1ll * n * (n - 1) / 2;}
int R[maxn];
void NTT(int* a,int n,int f){
for (int i = 0; i < n; i++) if (i < R[i]) swap(a[i],a[R[i]]);
for (int i = 1; i < n; i <<= 1){
int gn = qpow(G,(P - 1) / (i << 1));
for (int j = 0; j < n; j += (i << 1)){
int g = 1,x,y;
for (int k = 0; k < i; k++,g = 1ll * g * gn % P){
x = a[j + k],y = 1ll * g * a[j + k + i] % P;
a[j + k] = (x + y) % P,a[j + k + i] = ((x - y) % P + P) % P;
}
}
}
if (f == 1) return;
int nv = qpow(n,P - 2); reverse(a + 1,a + n);
for (int i = 0; i < n; i++) a[i] = 1ll * a[i] * nv % P;
}
int A[maxn],B[maxn],c[maxn],ans,N,fac[maxn],inv[maxn],fv[maxn];
void init(){
fac[0] = fac[1] = inv[0] = inv[1] = fv[0] = fv[1] = 1;
for (int i = 2; i <= N; i++){
fac[i] = 1ll * fac[i - 1] * i % P;
inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
fv[i] = 1ll * fv[i - 1] * inv[i] % P;
}
}
void Inv(int deg,int* a,int* b){
if (deg == 1){b[0] = qpow(a[0],P - 2); return;}
Inv((deg + 1) >> 1,a,b);
int L = 0,n = 1;
while (n < (deg << 1)) n <<= 1,L++;
for (int i = 1; i < n; i++) R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));
for (int i = 0; i < deg; i++) c[i] = a[i];
for (int i = deg; i < n; i++) c[i] = 0;
NTT(c,n,1); NTT(b,n,1);
for (int i = 0; i < n; i++)
b[i] = 1ll * ((2ll - 1ll * c[i] * b[i] % P) + P) % P * b[i] % P;
NTT(b,n,-1);
for (int i = deg; i < n; i++) b[i] = 0;
}
int main(){
N = read(); init();
for (int i = 0; i <= N; i++) A[i] = 1ll * qpow(2,C(i)) * fv[i] % P;
Inv(N + 1,A,B);
A[0] = 0;
int n = 1,L = 0;
while (n <= (N << 1)) n <<= 1,L++;
for (int i = 1; i < n; i++) R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));
NTT(A,n,1); NTT(B,n,1);
for (int i = 0; i < n; i++) A[i] = 1ll * A[i] * B[i] % P;
NTT(A,n,-1);
REP(i,N){
if (i == 1) puts("1");
else if (i == 2) puts("-1");
else printf("%lld\n",1ll * fac[i - 1] * qpow(2,C(i) - i) % P * qpow(1ll * A[i] * fac[i] % P,P - 2) % P);
}
return 0;
}

最新文章

  1. 关于搭建webservice以及无法通过URL访问的简易解决办法
  2. JavaWeb 学习005-4个页面,5条sql语句(添加、查看、修改、删除)
  3. DOM 事件
  4. Java for LeetCode 217 Contains Duplicate
  5. 有关servlet初学者的资源和建议
  6. Windows-009-Win7 操作系统安装图文详解
  7. linq 分类
  8. 性能测试vs负载测试vs压力测试-概念普及
  9. 准备在新项目中使用pgsql【资源收集】
  10. hdu1978How many ways (记忆化搜索+DFS)
  11. Memcached安装配置最大使用内存
  12. hadoop2 YARN/Mv2中 ApplicationMaster相关问题及介绍
  13. leetcode — distinct-subsequences
  14. Thymeleaf中href与 th:href的区别
  15. bootbox.js官方文档
  16. druid 连接Oracle时出现的错误
  17. 第一个Django页面(2)
  18. inst_for_mysql5.7.sh
  19. SharePoint 删除废弃站点步骤
  20. NetCore的控制台应用中搭建WebServer的方法

热门文章

  1. facebook和twitter的截图分享
  2. 关于linux-centos7 安装完成git后npm突然无法使用问题处理
  3. Linux虚拟机安装教程
  4. linux下自己安装软件做成命令
  5. LIFI热火下的VLC基本链路、标准及发展问题
  6. servlet 和 threadlocal 与 web容器(理解threadlocal)
  7. Daily Scrumming* 2015.10.30(Day 11)
  8. Daily scrum 2015.10.19
  9. IO异常 的处理
  10. 软工实践-Beta 冲刺 (4/7)