Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2046
Solution:
This aspect of recursion is closely related to mathematics, so I will take a look at the relevant knowledge. This question is a simple question and can be thought out.
Because can only put 1X2 specifications of the bone card, then, the n size of the grid can only be obtained from N-1 and N-2, n-1 when we add a 2x1 grid, vertical put, there can be f (n-1) Put method, N-2 when we can increase 2 × 2 lattice, 2 are placed horizontally, there can be f (n-2) method.
The idea of this question is the same as that of super step. N state can be obtained from n-1 state and N-2 state, so it can be solved by recursion. (DP thinking is also acceptable)
In addition, when n is relatively large, it may exceed int, so you can test it. It is impossible to use a large number.
CodeAs follows:
# Include <iostream >#include <cstdio> using namespace STD ;__ int64 DP [55] = {0, 1, 2, 3}; void fun () {for (INT I = 4; I <= 50; ++ I) DP [I] = DP [I-1] + dp [I-2];} int main () {int N; fun (); While (scanf ("% d", & N )! = EOF) printf ("% i64d \ n", DP [N]); Return 0 ;}