Recursive formula F [I] = 3 * f [I-1] + F [I-2]-f [1-3] (I> = 3)
The general formula is f [I] = 2 * (F [0] + F [1] +... + F [n-3]) + 3 * f [N-2] + 2 * f [n-1]
There may be two cases in the range of 1, that is, two squares or one rectangle.
There are three cases in which the range with the length of 2 is removed from the range with the length of 1, that is, the two squares above, the following rectangle, and the upside down and upside down, there are two rectangles, a total of three
If you want to repeat the range with a length greater than or equal to 3 without having a length of 2, you can only overlap two rectangles with one other. Fill the square at the vacancy. There are two kinds
The above generic formula is used to obtain the recursive formula.
# Include <iostream> # include <cstring> using namespace STD; int f [1000001]; int main () {INT cases, O; int N; memset (F, 0, sizeof (f); F [0] = 1; F [1] = 2; F [2] = 7; For (INT I = 3; I <= 1000001; I ++) {f [I] = (3 * f [I-1] + F [I-2]-f [I-3] + 10) % 10; // to prevent negative modulo errors, add 10} CIN> cases; for (O = 1; O <= cases; O ++) {CIN> N; cout <F [N] <Endl;} return 0 ;}