Bzoj5093: 圖的價值
阿新 • • 發佈:2018-02-21
() print ++i play printf gpo amp 理解 c++
題面
Bzoj
Sol
一張無向無重邊自環的圖的邊數最多為\(\frac{n(n-1)}{2}\)
考慮每個點的貢獻
\[n*2^{\frac{n(n-1)}{2} - (n-1)}\sum_{i=0}^{n-1}i^kC(n-1, i)\]
很好理解
考慮後面的\(\sum_{i=0}^{n-1}i^kC(n-1, i)\)
\(i^k\)這裏把它用第二類斯特林數表示出來
那麽就是
\[\sum_{i=0}^{n-1}\sum_{j=0}^{i}S(k, j) j!C(i, j)\]
\[=\sum_{j=0}^{n-1}S(k, j)j!\sum_{i=j}^{n-1}C(n-1,i)C(i,j)\]
考慮\(\sum_{i=j}^{n-1}C(n-1,i)C(i,j)\)
就是\(C(n-1, j)\sum_{i=j}^{n-1}C(n-1, i-j)=C(n-1,j)2^{n-1-j}\)
帶回去
\[\sum_{j=0}^{n-1}j!C(n-1,j)2^{n-1-j}S(k, j)\]
\[=\sum_{j=0}^{n-1}\frac{(n-1)!}{(n-1-j)!}2^{n-1-j}S(k,j)\]
又由於\(i>j\)時\(S(i, j)=0\),\(n\)很大枚到\(k\)就可以了
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int Zsy(998244353);
const int Phi(998244352);
const int G(3);
const int _(8e5 + 5);
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9' ; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int n, k, ans, A[_], B[_], l, N, r[_], mx, fac[_], inv[_];
IL int Pow(RG ll x, RG ll y){
RG ll ret = 1;
for(; y; y >>= 1, x = x * x % Zsy) if(y & 1) ret = ret * x % Zsy;
return ret;
}
IL void NTT(RG int* P, RG int opt){
for(RG int i = 0; i < N; ++i) if(i < r[i]) swap(P[i], P[r[i]]);
for(RG int i = 1; i < N; i <<= 1){
RG int W = Pow(G, Phi / (i << 1));
if(opt == -1) W = Pow(W, Zsy - 2);
for(RG int p = i << 1, j = 0; j < N; j += p)
for(RG int w = 1, k = 0; k < i; ++k, w = 1LL * w * W % Zsy){
RG int X = P[k + j], Y = 1LL * w * P[k + j + i] % Zsy;
P[k + j] = (X + Y) % Zsy, P[k + j + i] = (X - Y + Zsy) % Zsy;
}
}
if(opt == 1) return;
RG int Inv = Pow(N, Zsy - 2);
for(RG int i = 0; i < N; ++i) P[i] = 1LL * P[i] * Inv % Zsy;
}
IL void Mul(){
for(N = 1; N <= mx + mx; N <<= 1) ++l;
for(RG int i = 0; i < N; ++i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
NTT(A, 1); NTT(B, 1);
for(RG int i = 0; i < N; ++i) A[i] = 1LL * A[i] * B[i] % Zsy;
NTT(A, -1);
}
IL void Up(RG int &x, RG int y){
x += y;
if(x >= Zsy) x -= Zsy;
}
int main(RG int argc, RG char* argv[]){
n = Input(), k = Input(), mx = min(n - 1, k);
fac[0] = 1;
for(RG int i = 1; i <= mx; ++i) fac[i] = 1LL * i * fac[i - 1] % Zsy;
inv[mx] = Pow(fac[mx], Zsy - 2);
for(RG int i = mx - 1; ~i; --i) inv[i] = 1LL * inv[i + 1] * (i + 1) % Zsy;
for(RG int i = 0; i <= mx; ++i){
A[i] = B[i] = inv[i];
B[i] = 1LL * B[i] * Pow(i, k) % Zsy;
if(i & 1) A[i] = Zsy - A[i];
}
Mul(); RG int Inv = Pow(2, Zsy - 2);
for(RG int i = 0, e = 1, x = n - 1, pw = Pow(2, n - 1); i <= mx; ++i, --x){
Up(ans, 1LL * e * pw % Zsy * A[i] % Zsy);
e = 1LL * e * x % Zsy;
pw = 1LL * pw * Inv % Zsy;
}
ans = 1LL * n * Pow(2, 1LL * n * (n - 1) / 2 - n + 1) % Zsy * ans % Zsy;
printf("%d\n", ans);
return 0;
}
Bzoj5093: 圖的價值