[Sword refers to Offer] The rectangle is covered, and the sword refers to the offer rectangle.

Source: Internet
Author: User

[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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.