版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
title: "题解 - [POJ 3734] Gaussian Prime Factors" categories:
Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of painting. Suppose there are N blocks in a line and each block can be paint red, blue, green or yellow. For some myterious reasons, Panda want both the number of red blocks and green blocks to be even numbers. Under such conditions, Panda wants to know the number of different ways to paint these blocks.
The first line of the input contains an integer T(1≤T≤100), the number of test cases. Each of the next T lines contains an integer N(1≤N≤10^9) indicating the number of blocks.
For each test cases, output the number of ways to paint the blocks in a single line. Since the answer may be quite large, you have to module it by 10007.
2
1
2
2
6
PKU Campus 2009 (POJ Monthly Contest – 2009.05.17), Simon
给 $n$ 个方块排成一排, 每个方块都要染上红绿蓝黄四种颜色之一, 求红色方块和绿色方块个数均为偶数的染色方案数
显然答案应为
无限制的方案数 - 红色方块为奇数的方案数 - 绿色方块为奇数的方案数 + 红色和绿色方块均为奇数的方案数
即
$$ 4^n-2A+B\tag{1} $$
其中
由二项式定理和多项式定理, 有
将 $\text{(4)}$, $\text{(5)}$ 代入 $\text{(1)}$, 则答案为
$$ 4^{n-1}+2^{n-1} $$
设红色, 绿色, 蓝色, 黄色对应的 EGF 分别为 $F_r,F_g,F_b,F_y$ 有
令合法方案对应的 EGF 为 $G$, 显然 $\partial G\leqslant n$, 则有
$$ \begin{aligned} G&=F_rF_gF_bFy\ &={e^{4x}+2e^{2x}+1\over4}-o(x^n)\ &=\frac{1}{4}+\frac{1}{4}\sum{i=0}^n(4^i+2^{i+1})\frac{x^i}{i!} \end{aligned} $$
由于 $n\geqslant 1$, 所以我们可以忽略掉 $G$ 的常数项, 则答案为
$$ {4^n+2^{n+1}\over4}=4^{n-1}+2^{n-1} $$
设 $Fi=(f{i1},f{i2},f{i3},f_{i4})^T$ 表示染色序列长度为 $i$ 时的状态, 其中
则
$$ Fi=\begin{bmatrix} 2&1&1&0\ 1&2&0&1\ 1&0&2&1\ 0&1&1&2 \end{bmatrix}F{i-1} $$