WC模拟(1.12) T2 小C的锦标赛

小C的锦标赛

题目背景:

1.12 WC模拟T2

分析:多项式求逆

 

考场上本以为可以水到部分分,结果发现自己连规律都找不到······

30 % k = 3

结论:我们发现,如果不存在大小为3的环,说明原图是一个DAG,而DAG的数量为n!

证明:为什么原图是一个DAG,这是个好问题,但是我只会感性理解,我只会DAG的数量为什么是n!,考虑,对于某一个top序,连边的方式是确定的,因为两两之间都有连边,那么连边方式只能是从top序小的到top序大的,那么每一种top序,只能对应一个DAG,而top序一共有n!个,所以DAGn

 

30% : k = n

结论:竞赛图中,一个n(n >= 3)个点的强连通分量中一定包含有长度为i(2 <= i <= n)的简单环

 

证明:不妨采用归纳证明,在n = 3时该结论显然成立,n = 1时也可以看作成立。否则考虑强连通分量中的任意一个点S,如果将这个点删去,可能产生若干个新的强连通分量。将这些分量视为一些点,则根据之前的定理,它们的拓扑序是确定的,且拓扑序在前的强连通分量内的所有点都向拓扑序在后的所有点有连边.设按拓扑序排序后的强连通分量为G1G2,,Gm。考虑这样构造出一个大小为n的环:à G1 à G2……Gm à S,如果这个结论对较小的强连通分量成立,那么我们在任意一个分量Gi中,从任意一个点开始一定可以找到一条路径遍历其中的所有点.又因为SG1以及GmS都一定至少有一条边(否则整个图不强连通),所以一定可以找到一个这样的构造,得到一个大小为n的环。然后考虑大小小于n的环,如果m = 1(即包含一个n - 1的强连通分量),那么可以归纳到n - 1的情况.否则,由于拓扑序靠前强连通分量中的所有点向靠后的所有点都有连边,我

们可以在大小为n的环的基础上任意跳过一些点,不难发现可以构造出任意大小的环。

 

那么现在问题转化为,对于n个点的竞赛图,有多少个可以形成n个点的强连通分量,令这个答案为f(n),考虑补集转化为求n个点的竞赛图,有多上个不形成n个点的强连通分量,这个可以通过枚举top序最靠前的强连通分量的大小来完成。

定义 ,如果第一个强连通分量大小为i,从n个点中任意选择i个点形成,那么这i个点与其他点的连边,一定是从这i个点出发,到其他点,其他点可以任意,那么可以得到:



多加1是因为f(0)无法表示,由此我们可以利用多项式求逆在O(nlogn)的时间里解决

 

100%

有了上面的结论,我们可以把问题转化为,求有多少个大小为n的竞赛图,其中存在一个大小大于等于k的强连通分量,同样转化为补集思想,求有多少个大小为n的竞赛图中只存在小于k的强连通分量,令这个答案为s(n),那么,同样的枚举top序最靠前的强连通的大小:


1同样是因为s(0),并且F - f(0) - 1,可以简单看作是将F的常数项换成-1,所以说我们仍然用多项式求逆O(nlogn)就可以解决了。

据说上式可以常系数线性递推,但是因为代码复杂度(wo bu hui)所以就不想在意了······

 

Source:

 /*
	created by scarlyw
*/
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <set>
#include <queue>
#include <ctime>
#include <bitset>

inline char read() {
	static const int IN_LEN = 1024 * 1024;
	static char buf[IN_LEN], *s, *t;
	if (s == t) {
		t = (s = buf) + fread(buf, 1, IN_LEN, stdin);
		if (s == t) return -1;
	}
	return *s++;
}

/*
template<class T>
inline void R(T &x) {
	static char c;
	static bool iosig;
	for (c = read(), iosig = false; !isdigit(c); c = read()) {
		if (c == -1) return ;
		if (c == '-') iosig = true;	
	}
	for (x = 0; isdigit(c); c = read()) 
		x = ((x << 2) + x << 1) + (c ^ '0');
	if (iosig) x = -x;
}
//*/

const int OUT_LEN = 1024 * 1024;
char obuf[OUT_LEN], *oh = obuf;
inline void write_char(char c) {
	if (oh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), oh = obuf;
	*oh++ = c;
}

template<class T>
inline void W(T x) {
	static int buf[30], cnt;
	if (x == 0) write_char('0');
	else {
		if (x < 0) write_char('-'), x = -x;
		for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48;
		while (cnt) write_char(buf[cnt--]);
	}
}

inline void flush() {
	fwrite(obuf, 1, oh - obuf, stdout);
}

///*
template<class T>
inline void R(T &x) {
	static char c;
	static bool iosig;
	for (c = getchar(), iosig = false; !isdigit(c); c = getchar())
		if (c == '-') iosig = true;	
	for (x = 0; isdigit(c); c = getchar()) 
		x = ((x << 2) + x << 1) + (c ^ '0');
	if (iosig) x = -x;
}
//*/

const int MAXN = 400000 + 10;
const int mod = 998244353;
const int g = 3;

int m, k, n;
int fac[MAXN], inv_fac[MAXN], h[MAXN], s[MAXN], f[MAXN], temp[MAXN];

inline int mod_pow(int a, long long b) {
	int ans = 1;
	for (; b; b >>= 1, a = (long long)a * a % mod)
		if (b & 1) ans = (long long)ans * a % mod;
	return ans;
}

inline void ntt(int *a, int n, int f) {
	for (int i = 0, j = 0; i < n; ++i) {
		if (i > j) std::swap(a[i], a[j]);
		for (int k = n >> 1; (j ^= k) < k; k >>= 1);
	}
	for (int i = 1; i < n; i <<= 1) {
		long long wn = mod_pow(g, (mod - 1) / (i << 1));
		for (int j = 0; j < n; j += (i << 1)) {
			long long w = 1;
			for (int k = 0; k < i; ++k, w = w * wn % mod) {
				long long t = (long long)w * a[i + j + k] % mod;
				a[i + j + k] = (a[j + k] - t + mod) % mod;
				a[j + k] = (a[j + k] + t) % mod;
			}
		}
	}
	if (f == -1) {
		std::reverse(a + 1, a + n);
		long long inv = mod_pow(n, mod - 2);
		for (int i = 0; i < n; ++i) a[i] = (long long)a[i] * inv % mod;
	}
}

inline void inverse(int *a, int *b, int n) {
	if (n == 1) return (void)(b[0] = mod_pow(a[0], mod - 2));
	inverse(a, b, n >> 1), n <<= 1;
	for (int i = 0; i < n / 2; ++i) temp[i] = a[i], temp[i + n / 2] = 0;
	ntt(temp, n, 1), ntt(b, n, 1);
	for (int i = 0; i < n; ++i) b[i] = (2LL * b[i] % mod - 
		(long long)temp[i] * b[i] % mod * b[i] % mod + mod) % mod;
	ntt(b, n, -1);
	for (int i = n / 2; i < n; ++i) b[i] = 0;
}

inline void solve() {
	R(m), R(k), fac[0] = 1, h[0] = 1;
	for (n = 1; n <= m; n <<= 1) ;
	for (int i = 1; i < n; ++i) fac[i] = (long long)fac[i - 1] * i % mod;
	inv_fac[n - 1] = mod_pow(fac[n - 1], mod - 2);
	for (int i = n - 2; i >= 0; --i) 
		inv_fac[i] = (long long)inv_fac[i + 1] * (i + 1) % mod;
	for (int i = 1; i < n; ++i) 
		h[i] = (long long)mod_pow(2, (long long)i * (i - 1) / 2) 
			* inv_fac[i] % mod;
	inverse(h, f, n), f[0] = mod - 1;
	for (int i = 1; i < k; ++i) f[i] = mod - f[i];
	for (int i = k; i < n; ++i) f[i] = 0;
	inverse(f, s, n);
	std::cout << ((long long)h[m] * fac[m] % mod + 
		(long long)s[m] * fac[m] % mod) % mod;
}

int main() {
	freopen("tournament.in", "r", stdin);
	freopen("tournament.out", "w", stdout);
	solve();
	return 0;
}

猜你喜欢

转载自blog.csdn.net/scar_lyw/article/details/80211805