E - Many Optimization Problems 解説 by evima
Count the number of cases where the answer is at most \(K\). For the decision problem, we can proceed greedily, starting from a state where the initial remainder is \(v = 0\), replacing \(v\) with \(\max(v+A_i-K,0)\), and if \(v\) is always at most \(K\), it is possible; otherwise, it is impossible.
Let the sequence of transitions of \(v\) be \((v_0,v_1,\dots,v_N)\). (Let \(v_0 = 0\).) Consider the characteristics of the sequence corresponding to this \(v\). They are mainly divided into the following three types:
- When $v_i,v_{i+1} = 0$ $X_i$ can take any value between $0$ and $K$, inclusive.
- When $v_l=v_r=0$ and $v_{l+1},v_{l+2},\dots,v_{r-1}$ are at least $1$ $X_l,X_{l+1},\dots,X_{r-2}$ are all $K$, and $X_{r-1}$ can take any value between $0$ and $K-v_{r-1}$, inclusive.
- When $v_l=0$ and $v_{l+1},v_{l+2},\dots,v_{N}$ are at least $1$ $X_l,X_{l+1},\dots,X_{N-1}$ are all $K$, and $X_{N}$ is $K-v_{r-1}$.
Consider the generating function with \(x\) as the sum of \(X\) and \(y\) as the length of the sequence. For each of the above, we have:
\[ y(1+x+...+x^K) = \frac{y(1-x^{K+1})}{1-x}\]
\[ \left(\sum_{i \ge 2} y^iK^{i-2}x^{(i-1)K} \right) (Kx + (K-1)x^2 + ... + x^K) = \frac{y^2x^K(x-(K+1)x^{K+1}+Kx^{K+2})}{(1-Kyx^K)(1-x)^2}\]
\[ \left(\sum_{i \ge 1} y^iK^{i-1}x^{iK} \right) (x + x^2 + ... + x^K) = \frac{yx^K(x-x^{K+1})}{(1-Kyx^K)(1-x)}\]
Here, the last pattern can only be used once. Thus, the number of cases where the answer is at most \(K\) is
\[ \displaystyle [x^M y^N] \frac{1 + \frac{yx^K(x-x^{K+1})}{(1-Kyx^K)(1-x)}}{1 - \left(\frac{y(1-x^{K+1})}{1-x}\right)-\left(\frac{y^2x^K(x-(K+1)x^{K+1}+Kx^{K+2})}{(1-Kyx^K)(1-x)^2}\right)} \]
By the way, this expression can be written as a low-degree expression in \(x,x^K,k,\frac{y}{1-x}\). It becomes very long, but writing it out:
\[ \displaystyle [x^M y^N] \frac{1-Kx^K(1-x)\frac{y}{1-x} +x^K(x-x^{K+1}) \frac{y}{(1-x)}}{1-Kx^K(1-x)\frac{y}{1-x} - (1-x^{K+1})\left(1-Kx^K(1-x)\frac{y}{1-x}\right)\frac{y}{1-x} - x^K(x-(K+1)x^{K+1}+Kx^{K+2}) \left(\frac{y}{1-x}\right)^2} \]
Replace \(x,x^K,k,\frac{y}{1-x}\) with \(p,q,r,s\), and let \(f_{a,b,c,d}\) be the coefficient of \(p^aq^br^cs^d\) when expanding the above expression. Here, all terms in the denominator contain \(s\), so the coefficients are \(0\) except for parts where \(a,c \le d,b \le d+1\). Taking this into account, if we replace \(f_{a,b,c}\) with \(f_{a,b,c,N}\), the problem is reduced to finding:
\[ [x^M] \sum_{K \ge 0} \sum_{a,b,c} \frac{f_{a,b,c}x^a x^{Kb} K^c}{(1-x)^N}. \]
Although \(f_{0,0,0} = 1\), considering that what we are currently finding is the sum of the number of cases where the answer is at most \(K\), and what we should originally find is the sum of the number of cases where the answer is at least \(K\), \(f_{0,0,0}\) cancels out in the end, so there is no problem. Note that \(b \ge 1\) at this point. Here, if we fix \(a,b,c\), the expression becomes
\[ \frac{f_{a,b,c} x^a}{(1-x)^N} \sum_{K \le 0} x^{Kb} K^c \]
and the sigma part is expressed as \(\displaystyle \frac{P(x^b)}{(1-x^b)^{c+1}}\) by some \(c\)-degree polynomial \(P(x)\). That is,
\[\sum_{K \ge 0} \sum_{a,c} \frac{f_{a,b,c}x^a x^{Kb} K^c}{(1-x)^N} \]
when \(b\) is fixed has a representation \(\displaystyle \frac{Q(x)}{(1-x)^N(1-x^b)^{N+1}}\), which naturally means it also has a representation \(\displaystyle \frac{R(x)}{(1-x^b)^{2N+1}}\). So, if we let \(d = M \bmod b\), \([x^{d+bk}] \displaystyle \frac{R(x)}{(1-x^b)^{2N+1}}(k = 0,1,2,...)\) is expressed as \(g(k)\) by some \(2N\)-degree polynomial \(g(x)\).
We then only need to find the coefficient sequence in the range \(k \le 2N\). Since we only need to consider \(a\) and \(c\) at most \(N\) and \(K\) at most \(2N\), we can find the coefficient sequence in \(\mathrm{O}(N^3)\) for one \(b\), and apply polynomial interpolation in \(\mathrm{O}(N^2)\) to solve this problem in \(\mathrm{O}(N^4)\) overall.
投稿日時:
最終更新: