.article-info-tag,button{text-transform:uppercase}.day,.postMeta,.postSticky{position:relative}.postTitle a:link,html{-webkit-tap-highlight-color:transparent}#blog-calendar,.code-copay-btn,.code-hljs-len,.hidden{visibility:hidden}#EntryTag,#blogTitle h1{margin-top:20px}#EntryTag a,.postSticky{background:#6fa3ef}#blogTitle h1 a:hover,.dayTitle a,a,a:active,a:link,a:visited{color:#5c8ec6}#calendar table a:hover,#navList a:hover,.postDesc a:hover,a:active,a:hover,a:link,a:visited,button{text-decora…ryTag a:visited{color:#666}#BlogPostCategory a,#EntryTag a{height:20px;line-height:20px;color:#fff!important;padding:3px 5px;border-radius:3px;margin:2px 5px 0;text-decoration:none;font-size:14px}#BlogPostCategory a:hover,#EntryTag a:hover{transition:all .3s linear 0s;opacity:.8}#topics .postDesc{padding-left:0;width:100%;text-align:left;color:#666;margin-top:5px;background:0 0}.feedbackListSubtitle-louzhu:after,.feedbackListSubtitle:after,.feedbackListSubtitle:before{top:11px;right:100%;left:-1

Luogu P5396 第二类斯特林数 列 题解

Description

给定 \(n,k\),求

\[\begin{Bmatrix} 0 \\k \end{Bmatrix},\begin{Bmatrix} 1 \\k \end{Bmatrix},\cdots,\begin{Bmatrix} n \\k \end{Bmatrix} \]

即一列的第二类斯特林数,答案对 \(167772161\) 取模。

限制:\(1\le n,k< 2^{17}\)

Solution

考虑第二类斯特林数的递推式:

\[\begin{Bmatrix} n \\k \end{Bmatrix}=\begin{Bmatrix} n-1 \\k-1 \end{Bmatrix}+k\begin{Bmatrix} n-1 \\k \end{Bmatrix} \]

\[f_k(z)=\sum_{n\ge 0}\begin{Bmatrix} n \\k \end{Bmatrix}z^n \]

\[\begin{aligned} f_k(z)&=\sum_{n\ge 0}\begin{Bmatrix} n \\k \end{Bmatrix}z^k\\ &=\sum_{n\ge 0}\begin{Bmatrix} n-1 \\k-1 \end{Bmatrix}z^n+k\sum_{n\ge 0}\begin{Bmatrix} n-1 \\k \end{Bmatrix}z^n\\ &=zf_{k-1}(z)+kzf_k(z) \end{aligned} \]

解得 \(f_k(z)=\dfrac{z}{1-kz}f_{k-1}(z)\)。由于 \(f_0(z)=1\),所以

\[f_k(z)=\dfrac{z^k}{(1-z)(1-2z)\cdots(1-kz)}=\dfrac{z^k}{\displaystyle\prod_{j=1}^k(1-zj)} \]

只需用分治乘法算出分母求逆再平移即可。

时间复杂度:\(\mathcal O(n\log^2n)\)

posted @ 2022-03-23 02:26  feicheng  阅读(5)  评论(0编辑  收藏  举报