There are rows of n squares, with red, pink, green three-color coating each lattice, each lattice painted a color, the requirements of any adjacent squares can not be the same colour, and the first and the first two blocks also different colors. All the requirements of the coating method.
F (n) =f (n-1) +2*f (n-2);
The idea of wrong line:
When n numbered elements are placed in n numbered positions, the number of methods that do not correspond to the number of the element and the position number is expressed in M (n), then M (n-1) indicates that the n-1 number element is placed in the n-1 number position, the number of methods that do not correspond, and other analogies.
The first step, put the nth element in a position, such as position k, altogether there are n-1 methods;
The second step, put the element numbered K, there are two cases. 1, put it to position N, then, for the remaining n-2 elements, there is M (n-2) method, 2, do not put it to position N, at this time, for this n-1 element, there is M (n-1) method;
The Comprehensive
M (n) = (n-1) [M (n-2) +m (n-1)]
Specifically, M (1) =0,m (2) =1 Congruent Triangular Division number (HDU 1396)a[i] = a[i-1]+i* (i+1)/2;
Some mathematical formulas