某天在考場上碰到了板題,但是沒看出來,當場爆零。
簡單來講,\(\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)\)求行