ZJU-ICPC Summer 2020 Contest 9 F-FFT
引用部落格:
帶邊數的無向連通圖計數
Pretty is a smart girl who loves math very much.
She has already learned FFT algorithm.
She loves traveling and she is looking forward to visiting more cities.
A country is defined as Pretty Country if and only if every two cities in the country have a path.
Notice the road is biconditional.
Given the number of roads m and the number of cities \(n\), Pretty wants to know the number of Pretty Country.
Since the number may be very big, please mod \(998244353\).
Here mod means modulo operation.
Input
One line containing an integer \(n\). (\(1 \leq n \leq 100\))
\(m\) is \(0,1,2,3,\dots, \frac{n(n-1)}{2}\)
Output
\(\frac{n(n-1)}{2}\) lines.
The number means the answer.
Examples
inputCopy
2
outputCopy
0
1
inputCopy
5
outputCopy
0
0
0
0
125
222
205
120
45
10
1
#include<bits/stdc++.h> using namespace std; #define d(x) ( x * (x - 1) / 2) const int mod = 998244353; int n; long long H[105][5000],F[5000]; long long fac[5005],inv[5005]; long long ksm(long long x,long long y){ long long z = 1; while(y){ if(y & 1) z = z * x % mod; y >>= 1; x = x * x % mod; } return z; } long long C(int n,int m){ if(n < m || m < 0) return 0; if(n == m || m == 0) return 1; return fac[n] * inv[m] % mod * inv[n - m] % mod; } int main(){ fac[0] = 1; for(int i = 1; i <= 5000; ++ i) fac[i] = fac[i - 1] * i % mod; inv[5000] = ksm(fac[5000],mod - 2); for(int i = 4999; i >= 0; -- i) inv[i] = inv[i + 1] * (i + 1) % mod; scanf("%d",&n); for(int i = 1; i <= n; ++ i) H[i][d(i)] = 1; for(int i = 1; i <= n; ++ i) for(int j = d(i); j >= 0; -- j){ if(H[i][j]){ for(int k = 1; i + k <= n; ++ k){ H[i + k][j + d(k)] += mod - H[i][j] * C(i + k - 1, k) % mod; H[i + k][j + d(k)] %= mod; } } } for(int j = 0; j <= d(n); ++ j){ for(int k = j; k <= d(n); ++ k) F[j] += H[n][k] * C(k,j) % mod , F[j] %= mod; F[j] = (F[j] % mod + mod) % mod; printf("%lld\n",F[j]); } return 0; }