Loading

「题解」[CF1548C] The Three Little Pigs

\(f_{i, j}\ (0 \le j \le 2)\)\(\sum^{n - 1}_{i = 0} \binom{3i + m}{x}\) 的值,则对于一个询问 \(x\),答案为 \(f_{x, 0} + \binom{3n}{x}\)

那么显然有:

  • \(f_{i, 0} + f_{i, 1} + f_{i, 2} = \binom{3n}{i + 1}\)
  • \(f_{i, 1} = f_{i, 0} + f_{i - 1, 0}\)
  • \(f_{i, 2} = f_{i, 1} + f_{i - 1, 1}\)
  • 边界条件 \(f_{0, 0} = f_{0, 1} = f_{0, 2} = n\)

根据上述式子预处理递推求出 \(f\) 即可,时间复杂度 \(\Theta(n + q)\)

代码很简单就不放了。

posted @ 2021-08-02 16:09  Aestas16  阅读(81)  评论(2编辑  收藏  举报