某天在考场上碰到了板题,但是没看出来,当场爆零。
简单来讲,\(\left<\begin{matrix}n\\k\end{matrix}\right>\) 表示满足长度为 \(n\) 且恰好有 \(k\) 个位置满足 \(\pi_i < \pi_{i+1}\) 的排列 \(\pi\) (这样的位置后文记为“升高”)的个数。它的三角形前几行打出来长这样:
\[1 \]
\[1\space\space\space\space 0 \]
\[1\space\space\space\space 1 \space\space\space\space 0 \]
\[1\space\space\space\space 4\space\space\space\space 1\space\space\space\space 0 \]
\[1\space\space\space 11 \space\space\space 11 \space\space\space 1 \space\space\space 0 \]
\[1\space\space 26 \space\space\space 66 \space\space\space 26 \space\space\space 1 \space\space 0 \]
找规律?考场上找了很久也没找出来,还是老老实实dp。假设现在已经有了一个长度为 \(n\) 的排列,考虑 \(n\) 插入的位置带来的影响。
如果 \(n\) 插在最后边,则增加了一个升高,即有 \(\left<\begin{matrix}n-1\\k-1\end{matrix}\right>\) 的贡献。
如果 \(n\) 插在最前边,相当于什么都没干,即有 \(\left<\begin{matrix}n-1\\k\end{matrix}\right>\) 的贡献。
如果 \(n\) 插在任意一个升高的中间,则破坏了一个升高又新增了一个,也相当于啥也没干。即有 \(k\left<\begin{matrix}n-1\\k\end{matrix}\right>\) 的贡献。
如果 \(n\) 插在不是任意一个升高的中间,则新增了一个升高。即有 \((n-k-1)\left<\begin{matrix}n-1\\k-1\end{matrix}\right>\) 的贡献。
把贡献累加起来,有递推式:
\[\left<\begin{matrix}n\\k\end{matrix}\right>=(k+1)\left<\begin{matrix}n-1\\k\end{matrix}\right>+(n-k)\left<\begin{matrix}n-1\\k-1\end{matrix}\right> \]
然后这东西显然有对称性,即:
\[\left<\begin{matrix}n\\k\end{matrix}\right>=\left<\begin{matrix}n\\n-k-1\end{matrix}\right> \]
其实也可以用如下式子:
\[\left<\begin{matrix}n\\k\end{matrix}\right>=\sum_{i=0}^k\left(\begin{matrix}n+1\\i\end{matrix}\right)(k+1-i)^n(-1)^i \]
证明的话数学归纳法,往递推式代再推一大坨就好。它显然是个卷积的形式,可以直接\(\Theta(n\log n)\)求行