一个长度为 n n n的序列 h i h_i hi,每个数的取值范围为 [ 1 , m ] [1,m] [1,m]。
求恰好有 k k k处 h i < h i + 1 h_i
题目保证 n − k + 1 n-k+1 n−k+1不会很大。
n ≤ 2 20 − 10 n\le 2^{20}-10 n≤220−10
( n − k + 1 ) m ≤ 2 20 − 10 (n-k+1)m\le 2^{20}-10 (n−k+1)m≤220−10
恰好 k k k次升调比较难算,所以二项式反演,转化成至少 k k k次升调。
k k k次升调相当于 n − 1 − k n-1-k n−1−k次非升调,所以有 n − k n-k n−k段,每段都是升调。
设一段全是升调的生成函数为 F ( x ) F(x) F(x)。显然 F ( x ) = ∑ k ≥ 1 ( m k ) x k = ( 1 + x ) m − 1 F(x)=\sum_{k\ge 1} \binom{m}{k}x^k=(1+x)^m-1 F(x)=∑k≥1(km)xk=(1+x)m−1。
有 n − k n-k n−k段,所以答案为 [ x n ] F n − k ( x ) [x^n]F^{n-k}(x) [xn]Fn−k(x)。为了后面计算方便记 f ( x ) = F ( x ) x f(x)=\frac{F(x)}{x} f(x)=xF(x),于是答案为 [ x k ] f n − k ( x ) [x^k]f^{n-k}(x) [xk]fn−k(x)
把总答案的式子给写出来:
A N S = ∑ n = k + 1 N ∑ i ≥ k f n − i ( x ) [ x i ] ( i k ) ( − 1 ) i − k ANS=\sum_{n=k+1}^N\sum_{i\ge k} f^{n-i}(x)[x^i]\binom{i}{k}(-1)^{i-k} ANS=n=k+1∑Ni≥k∑fn−i(x)[xi](ki)(−1)i−k
= ∑ i = k N 1 − f N − i + 1 ( x ) 1 − f ( x ) [ x i ] ( i k ) ( − 1 ) i − k =\sum_{i=k}^N\frac{1-f^{N-i+1}(x)}{1-f(x)}[x^i]\binom{i}{k}(-1)^{i-k} =i=k∑N1−f(x)1−fN−i+1(x)[xi](ki)(−1)i−k
(这里已经假设了 k > 0 k>0 k>0,忽略了零次项)
= ∑ i = k N x N − i + 1 − F N − i + 1 ( x ) 1 − f ( x ) [ x N + 1 ] ( i k ) ( − 1 ) i − k =\sum_{i=k}^N\frac{x^{N-i+1}-F^{N-i+1}(x)}{1-f(x)}[x^{N+1}]\binom{i}{k}(-1)^{i-k} =i=k∑N1−f(x)xN−i+1−FN−i+1(x)[xN+1](ki)(−1)i−k
= [ x N + 1 ] 1 1 − f ( x ) ∑ i = k N ( i k ) ( − 1 ) i − k ( x N − i + 1 − F N − i + 1 ( x ) ) =[x^{N+1}]\frac{1}{1-f(x)}\sum_{i=k}^N\binom{i}{k}(-1)^{i-k}(x^{N-i+1}-F^{N-i+1}(x)) =[xN+1]1−f(x)1i=k∑N(ki)(−1)i−k(xN−i+1−FN−i+1(x))
现在主要问题变成了求 ∑ i = k N ( i k ) ( − 1 ) i − k F N − i + 1 ( x ) \sum_{i=k}^N \binom{i}{k}(-1)^{i-k}F^{N-i+1}(x) ∑i=kN(ki)(−1)i−kFN−i+1(x)
i = N + 1 i=N+1 i=N+1时显然没有 x N + 1 x^{N+1} xN+1项,所以放宽对 i i i的限制。
= ∑ i = k N + 1 ( i k ) ( − 1 ) i − k F N − i + 1 ( x ) =\sum_{i=k}^{N+1} \binom{i}{k}(-1)^{i-k}F^{N-i+1}(x) =i=k∑N+1(ki)(−1)i−kFN−i+1(x)
= ∑ i = k N + 1 ( i k ) ( − 1 ) i − k ( ( 1 + x ) m − 1 ) N − i + 1 =\sum_{i=k}^{N+1} \binom{i}{k}(-1)^{i-k}((1+x)^m-1)^{N-i+1} =i=k∑N+1(ki)(−1)i−k((1+x)m−1)N−i+1
暴力拆开,推若干步得:
= ∑ j = 0 N − k + 1 ( 1 + x ) m j ∑ i = k N − j + 1 ( i k ) ( N − i + 1 j ) ( − 1 ) N + k + 1 + j =\sum_{j=0}^{N-k+1}(1+x)^{mj}\sum_{i=k}^{N-j+1}\binom{i}{k}\binom{N-i+1}{j}(-1)^{N+k+1+j} =j=0∑N−k+1(1+x)mji=k∑N−j+1(ki)(jN−i+1)(−1)N+k+1+j
= ∑ j = 0 N − k + 1 ( 1 + x ) m j ( N + 2 j + k + 1 ) ( − 1 ) N + k + 1 + j =\sum_{j=0}^{N-k+1}(1+x)^{mj}\binom{N+2}{j+k+1}(-1)^{N+k+1+j} =j=0∑N−k+1(1+x)mj(j+k+1N+2)(−1)N+k+1+j
(组合意义:一个长度为 N + 2 N+2 N+2的表格,选 j + k + 1 j+k+1 j+k+1个格子;枚举第 k + 1 k+1 k+1个格子的位置(已经钦定是第几个,方案唯一),左边选 k k k右边选 j j j)
= ∑ i = 0 m ( N − k + 1 ) x i ∑ j = 0 N − k + 1 ( m j i ) ( N + 2 j + k + 1 ) ( − 1 ) N + k + 1 + j =\sum_{i=0}^{m(N-k+1)}x^i\sum_{j=0}^{N-k+1}\binom{mj}{i}\binom{N+2}{j+k+1}(-1)^{N+k+1+j} =i=0∑m(N−k+1)xij=0∑N−k+1(imj)(j+k+1N+2)(−1)N+k+1+j
这个东西可以用卷积算。