其他分享
首页 > 其他分享> > CF717A Festival Organization

CF717A Festival Organization

作者:互联网

更好的阅读体验

题意

一个合法的串定义为:长度在 \([l, r]\) 之间,且只含 \(0,1\),并且不存在连续 \(2\) 个或更多的 \(0\).
现在要选出 \(k\) 个长度相同的不同的合法的串,问有几种选法,答案模 \(10^9+7\).

\(1\le l\le r\le10^{18}, 1\le k\le200\).

题解

设 \(F_{i,j}\) 表示长度为 \(i\), 以 \(j\) 结尾的合法串个数.
有 $$\left{
\begin{array}{lr}
F_{i,0}=F_{i-1,1} & \
F_{i,1}=F_{i-1,0}+F_{i-1,1} &
\end{array}
\right.$$
即 $$\left{
\begin{array}{lr}
F_{i,0}=\text{Fib}{i} & \
F
{i,1}=\text{Fib}{i+1} &
\end{array}
\right.$$
所以答案 $$\text{Ans}=\sum\limits
{l+2\le i\le r+2}\begin{pmatrix}\text{Fib}_i\k\end{pmatrix}$$

\[\begin{align*} \text{Ans} =&\sum_{l+2\leq i\leq r+2} \begin{pmatrix}{\text{Fib}_i}\\k\end{pmatrix}\\ =&\frac{1}{k!}\sum_{l+2\le i\le r+2} {\text{Fib}_i}^{\underline{k}}\\ =&\frac{1}{k!}\sum_{l+2\le i\le r+2}\sum_{1\le j\le k}(-1)^{k-j}\begin{bmatrix}k\\ j \end{bmatrix}{\text{Fib}_i}^j\\ =&\frac{1}{k!}\sum_{1\le i\le k}(-1)^{k-i}\begin{bmatrix}k\\ i \end{bmatrix}\sum_{l+2\le j\le r+2}{\text{Fib}_j}^i \end{align*} \]

考虑带入斐波那契数的通项,令 \(A=\frac{1+\sqrt{5}}{2}, B=\frac{1-\sqrt{5}}{2}\)

\[\begin{align*} \text{Ans} =&\frac{1}{k!}\sum_{1\le i\le k}(-1)^{k-i}\begin{bmatrix}k\\ i \end{bmatrix}\sum_{l+2\le j\le r+2}[{\frac{1}{\sqrt{5}}(A^j-B^j)}]^i\\ =&\frac{1}{k!}\sum_{1\le i\le k}(-1)^{k-i}\begin{bmatrix}k\\ i \end{bmatrix}(\frac{1}{\sqrt{5}})^i\sum_{l+2\le j\le r+2}\sum_{0\le p\le i}\begin{pmatrix}i\\p\end{pmatrix}(-1)^p(A^{i-p}B^p)^j\\ =&\frac{1}{k!}\sum_{1\le i\le k}(-1)^{k-i}\begin{bmatrix}k\\ i \end{bmatrix}(\frac{1}{\sqrt{5}})^i\sum_{0\le j\le i}\begin{pmatrix}i\\j\end{pmatrix}(-1)^j\sum_{l+2\le p\le r+2}(A^{i-j}B^j)^p \end{align*} \]

等比数列求和快速计算式子后面部分
\(\Theta(k^2\times(\log l+\log r))\)

细节

本题涉及对 \(\sqrt{5}\) 的计算,然而在模 \(10^9+7\) 意义下 \(5\) 没有二次剩余,扩域维护即可

代码 codeforces submission 137205589

标签:begin,le,end,Festival,text,sum,frac,Organization,CF717A
来源: https://www.cnblogs.com/gzezfisher/p/cf717a.html