Loading

【题解】LOJ #6672(感谢强大 alpha!!1【4】)

考虑完整的一段的 GF 为 \(u\),那么答案为 \([x^n]u^{m}\)(令 \(m=k-1\))。

考虑 \(u\) 是什么,发现和此默慈金数相关 —— 我们令 \(M\) 为默慈金数的 GF,根据递推式 \(M_{n+1}=M_n+\sum\limits_{i=0}^{n-1}M_iM_{n-1-i}\),有 \(1+(x-1)M+x^2M^2=0\),即 \(M=\frac{1-x-\sqrt{1-2x-3x^2}}{2x^2}\)

于是 \(u\) 其实就是限定首尾两步得到的结果,即 \(u=x^2M+x=\frac{1+x-\sqrt{1-2x-3x^2}}{2}\),显然 \(u\) 是 D-finite 的。

此时 \(u'\) 有:

\[\begin{aligned} u'=\left(\frac{1+x-\sqrt{1-2x-3x^2}}{2}\right)'&=\frac{1}{2}\left(1+\frac{1+3x}{\sqrt{1-2x-3x^2}}\right)\\ &=\frac{1}{2}\frac{1-2x+3x^2+(1+3x)\sqrt{1-2x-3x^2}}{1-2x-3x^2}\\ &=\frac{1+x-(1+3x)u}{1-2x-3x^2} \end{aligned} \]

考虑令 \(H(x)=u^{m}\),有 \(mH=u\frac{H'}{u'}\),展开:

\[\begin{aligned} H'=H\cdot mu'u^{-1}&=H\cdot m\frac{(1+x){\color{red}{u^{-1}}}-1-3x}{1-2x-3x^2}\\ \end{aligned} \]

\(u^{-1}\) 直接写会很复杂。不过注意到 \(M\) 方程 \(1+(x-1)M+x^2M^2=0\) 的一根,而 \(M=\frac{u-x}{x^2}\),因此 \(u\) 是方程 \(u^2-(1+x)u+(x+x^2{})=0\) 的一根。根据韦达定理有 \(u_1\cdot u_2=x+x^2\)\(u_1+u_2=1+x\),不妨认为 \(u=u_1\),那么 \(u_2=1+x-u=(x+x^2){\color{red}{u^{-1}}}\) 。因此 \(u^{-1}=\frac{1+x-u}{x+x^2}\),带入:

\[\begin{aligned} H'=H\cdot mu'u^{-1}&=H\cdot m\frac{(1+x){\color{red}{u^{-1}}}-1-3x}{1-2x-3x^2}\\ &=H\cdot m\frac{(1+x){\color{red}{\frac{1+x-u}{x+x^2}}}-1-3x}{1-2x-3x^2}\\ &=H\cdot m\frac{1-3x^2-u}{x\left(1-2x-3x^2\right)}\\ \end{aligned} \]

但这还不够,因为根号下的部分并不好处理。我们尝试拆开 \(H''\)

\[\begin{aligned} H''&=m\left(H'\cdot \frac{1-3x^2-u}{x\left(1-2x-3x^2\right)}+H\cdot \left(\frac{1-3x^2-u}{x\left(1-2x-3x^2\right)}\right)'\right)\\ &=H\cdot m\left(m\frac{(1-3x^2-u)^2}{x^2\left(1-2x-3x^2\right)^2}+\left(\frac{1-3x^2-u}{x\left(1-2x-3x^2\right)}\right)'\right)\\ &=H\cdot m\left(m\frac{(1-3x^2-u)^2}{x^2\left(1-2x-3x^2\right)^2}+\frac{-(1-4x-6x^2+9x^4)+(1-4x-9x^2)u-x(1-2x-3x^2)u'}{x^2\left(1-2x-3x^2\right)^2}\right)\\ &=H\cdot m\left(m\frac{(1-3x^2-u)^2}{x^2\left(1-2x-3x^2\right)^2}+\frac{(1-3x-6x^2)u-(1-3x-5x^2+9x^4)}{x^2\left(1-2x-3x^2\right)^2}\right)\\ &=H\cdot m\left(m\frac{1-6x^2+9x^4-(2-6x^2)u+{\color{blue}{u^2}}}{x^2\left(1-2x-3x^2\right)^2}+\frac{(1-3x-6x^2)u-(1-3x-5x^2+9x^4)}{x^2\left(1-2x-3x^2\right)^2}\right)\\ &=H\cdot m\left(m\frac{1-6x^2+9x^4-(2-6x^2)u+{\color{blue}{(1+x)u-(x+x^2)}}}{x^2\left(1-2x-3x^2\right)^2}+\frac{(1-3x-6x^2)u-(1-3x-5x^2+9x^4)}{x^2\left(1-2x-3x^2\right)^2}\right)\\ &=H\cdot m\left(m\frac{-(1-x-6x^2)u+(1-x-7x^2+9x^4)}{x^2\left(1-2x-3x^2\right)^2}+\frac{(1-3x-6x^2)u-(1-3x-5x^2+9x^4)}{x^2\left(1-2x-3x^2\right)^2}\right)\\ \end{aligned} \]

此时我们尝试组合 \(H',H'',H\),我们发现:

\[\begin{aligned} H''&=H\cdot m\left(m\frac{-(1-x-6x^2)u+(1-x-7x^2+9x^4)}{x^2\left(1-2x-3x^2\right)^2}+\frac{(1-3x-6x^2)u-(1-3x-5x^2+9x^4)}{x^2\left(1-2x-3x^2\right)^2}\right)\\ &=H\cdot m\left(\frac{-\left(m(1-x-6x^2)-(1-3x-6x^2)\right)u}{x^2\left(1-2x-3x^2\right)^2}\right)+H\cdot m\left(\frac{m(1-x-7x^2+9x^4)-(1-3x-5x^2+9x^4)}{x^2\left(1-2x-3x^2\right)^2}\right)\\ &=H'\cdot m\left(\frac{m(1-x-6x^2)-(1-3x-6x^2)}{x(1+x)(1-3x)}\right)+H\cdot m\left(\frac{m(2x^2-3x^3-9x^4)-(4x^2-9x^3-9x^4)}{x^2\left(1-2x-3x^2\right)^2}\right)\\ &=H'\cdot \left(\frac{m(1-x-6x^2)-(1-3x-6x^2)}{x(1+x)(1-3x)}\right)+H\cdot m\left(\frac{m(2+3x)-(4+3x)}{(1+x)^2(1-3x)}\right)\\ \end{aligned} \]

也就是说:

\[\begin{aligned} x(1+x)^2(1-3x)H''=&H'\cdot (1+x)(m(1-x-6x^2)-(1-3x-6x^2))+\\ &H\cdot m(m(2x+3x^2)-(4x+3x^2))\\ \end{aligned} \]

递推即可。时间复杂度 \(O(n\log p)\)(上面的递推式有个逆元我不会预处理 ... 所以暴力算逆元)。

int n, k, inv[N], C0[3], C1[4], C2[5], H[N];

signed main () {
	IN (n), IN (k), -- k;
	if (k > n || ! k) return puts ("0"), 0;

	inv[1] = 1;
	lep (i, 1, n) inv[i] = mul (mod - mod / i, inv[mod % i]);

	// C0
	C0[1] = dec (mul (k, 2), 4);
	C0[2] = dec (mul (k, 3), 3);
	lep (i, 1, 2) C0[i] = mul (C0[i], k);

	// C1
	C1[0] = dec (mul (k, 1), 1);
	C1[1] = dec (mul (k, mod - 1), mod - 3);
	C1[2] = dec (mul (k, mod - 6), mod - 6);
	rep (i, 2, 0) pls (C1[i + 1], C1[i]);

	// C2
	C2[1] = 1, C2[2] = 2, C2[3] = 1;
	rep (i, 3, 1) sub (C2[i + 1], mul (C2[i], 3));

	// H
	H[k] = 1, H[k + 1] = k, H[k + 2] = add (k, (1ll * k * (k - 1) / 2) % mod);

	lep (i, k + 2, n - 1) {
		int ret = 0, coef = 0;

		sub (coef, mul (C2[1], mul (i + 1, i)));
		pls (ret, mul (H[i], mul (C2[2], mul (i, i - 1))));
		pls (ret, mul (H[i - 1], mul (C2[3], mul (i - 1, i - 2))));
		pls (ret, mul (H[i - 2], mul (C2[4], mul (i - 2, i - 3))));

		pls (coef, mul (C1[0], i + 1));
		sub (ret, mul (H[i], mul (C1[1], i)));
		sub (ret, mul (H[i - 1], mul (C1[2], i - 1)));
		sub (ret, mul (H[i - 2], mul (C1[3], i - 2)));

		sub (ret, mul (H[i - 1], C0[1]));
		sub (ret, mul (H[i - 2], C0[2]));

		H[i + 1] = mul (ret, qpow (coef, mod - 2));
	}

	printf ("%d\n", H[n]);
	return 0;
}
posted @ 2022-12-01 16:52  Qiuly  阅读(199)  评论(1编辑  收藏  举报