[Sword refers to Offer] The rectangle is covered, and the sword refers to the offer rectangle.
Problem description
We can use a 2*1 small rectangle to overwrite a larger rectangle either horizontally or vertically.
I would like to ask you to use n small rectangles of 2*1 to overwrite a large rectangle of 2 * n without overlap,
How many methods are there in total?
Solutions
N = 1-only one rectangle is placed horizontally.
N = 2-two solutions: horizontal and vertical rectangular
N = 3-n = 2 plus 1 transverse, n = 1 plus 2 vertical
N = 4-n = 3 plus 1 transverse, n = 2 plus 2 vertical
·
·
·
N = n-n = f (n-1) + f (n-2)
Fibonacci variant .....
Code Implementation
Class Solution {public: int rectCover (int number) {if (number = 0) return 0; else if (number = 1) {return 1 ;} else if (number = 2) {return 2;} return rectCover (number-1) + rectCover (number-2 );}};
If this problem is found, you can calculate a few items from n = 0 or 1 (the same as the regular number of fields in the middle and high school ), to find the relationship between two numbers or several numbers.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.