码迷,mamicode.com
首页 > 移动开发 > 详细

FZOJ4167 The Happy Prince and Other Tales 题解

时间:2020-06-01 12:04:31      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:end   题解   return   splay   The   div   and   pow   log   

The Happy Prince and Other Tales

给定长度为 \(n+1\) 的数列 \(\langle a_i\rangle_{i=0}^n\),请对于 \(\forall m\in[0,n]\) 输出 \(f_m(n)\bmod 998244353\)

\[f_m(n)=\sum_{i=0}^na_i\sum_{k=0}^ib^k\binom{m}{k}\binom{n-m}{i-k} \]

\((n\le 10^6,a_i,b< 998244353)\)

我们令

\[a_i=\sum_{j_1=0}^i\sum_{j_2=0}^{j_1}\cdots\sum_{j_p=0}^{j_{p-1}}\binom{i}{j_1}\binom{j_1}{j_2}\cdots\binom{j_{p-1}}{j_p}c_{j_p} \]

\[\begin{aligned} f_m(n)=&\sum_{i=0}^n\sum_{j_1=0}^i\sum_{j_2=0}^{j_1}\cdots\sum_{j_p=0}^{j_{p-1}}\binom{i}{j_1}\binom{j_1}{j_2}\cdots\binom{j_{p-1}}{j_p}c_{j_p}\sum_{k=0}^ib^k\binom{m}{k}\binom{n-m}{i-k} \=&\sum_{j_p=0}^nc_{j_p}\sum_{i=0}^n\sum_{j_1=0}^i\sum_{j_2=0}^{j_1}\cdots\sum_{j_{p-1}=j_p}^{j_{p-2}}\sum_{k=0}^ib^k\binom{m}{k}\binom{n-m}{i-k}\binom{i}{j_1}\binom{j_1}{j_2}\cdots\binom{j_{p-1}}{j_p} \\end{aligned} \]

存在

\[\begin{aligned} &\sum_{i_1=0}^n\sum_{i_2=0}^{i_1}\cdots\sum_{i_p=0}^{i_{p-1}}\binom{n}{i_1}\binom{i_1}{i_2}\cdots\binom{i_{p-1}}{i_p}\binom{i_p}{t}k^{i_1} \=&\sum_{i_1=0}^n\sum_{i_2=0}^{i_1}\cdots\sum_{i_p=0}^{i_{p-1}}\frac{n!}{(n-i_1)!(i_1-i_2)!\cdots(i_{p-1}-i_p)!(i_p-t)!t!}k^{i_1} \=&\sum_{\sum_{j=1}^pi_j=n-t}\frac{n!}{t!\prod_{j=1}^pi_j!}k^{n-i_1} \\end{aligned} \]

发现这是一 个多项式定理的形式,考虑生成函数,上式等于

\[[x^t](kp+kx+1)^n \]

重新观察 \(f_m(n)\),可以进行如下化简

\[\begin{aligned} f_m(n)=&\sum_{j_{p}=0}^nc_{j_p}\sum_{k=0}[x^k](1+bp+bx)^m[x^{j_p-k}](1+p+x)^{n-m} \=&\sum_{j_{p}=0}^nc_{j_p}[x^{j_p}](1+bp+bx)^m(1+p+x)^{n-m} \end{aligned} \]

我们令 \(p=-1\),带入得

\[f_m(n)=\sum_{i=n-m}^nc_i[x^{i-(n-m)}](1-b+bx)^m=\sum_{i=n-m}^nc_i\binom{m}{i-(n-m)}b^{i-(n-m)}(1-b)^{n-i} \]

这是多项式卷积的形式,即

\[\frac{f_m(n)}{m!}=\sum_{i}\frac{b^{m-(n-i)}}{(m-(n-i))!}\cdot\frac{(1-b)^{n-i}c_i}{(n-i)!} \]

我们现在来考虑如何求 \(c\),根据反演,有

\[c_i=\sum_{j_1=0}^i\sum_{j_2=0}^{j_1}\cdots\sum_{j_p=0}^{j_{p-1}}\binom{i}{j_1}\binom{j_1}{j_2}\cdots\binom{j_{p-1}}{j_p}(-1)^{i-j_1}(-1)^{j_1-j_2}\cdots(-1)^{j_{p-1}-j_p}a_{j_p} \]

发现这个仍是多项式定理的形式,即

\[c_i=\sum_{j=0}^i[x^j](-p+\sqrt[j]{a_j})^i=\sum_{j=0}^i\binom{i}{j}(-p)^{i-j}a_j=\sum_{j=0}^i\binom{i}{j}a_j \]

至此,共两次多项式卷积即可求出答案,时间复杂度 \(O(n\log n)\)

#include <iostream>

using i64 = long long;

namespace fio;

namespace ply;
using ply::MOD;
using ply::fac;
using ply::ifc;
using ply::pow;

const int N = 1000000 + 7;

int n;
i64 a[N], b, c[N];

int main() {
	fio::in(n), fio::in(b), ++n;
	for (int i = 0; i < n; ++i) fio::in(a[i]);

	static ply::polyT f, g, h;
	for (int i = 0; i < n; ++i)
		f[i] = ifc[i], g[i] = a[i] * ifc[i] % MOD;
	ply::mul(f, n, g, n, h);
	for (int i = 0; i < n; ++i)
		c[i] = h[i] * fac[i] % MOD;

	for (int i = 0; i < n; ++i)
		f[i] = pow(b, i) * ifc[i] % MOD,
		g[i] = pow(1 - b, i) * c[n - i - 1] % MOD * ifc[i] % MOD;
	ply::mul(f, n, g, n, h);
	for (int i = 0; i < n; ++i)
		fio::out((h[i] * fac[i] % MOD + MOD) % MOD), fio::put(‘\n‘);
	return 0;
}

FZOJ4167 The Happy Prince and Other Tales 题解

标签:end   题解   return   splay   The   div   and   pow   log   

原文地址:https://www.cnblogs.com/Ryedii-blog/p/13024104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!