Recursive fun problem

Source: Internet
Author: User

On the internet to see a recursive solution to the courseware, the feeling inside the problem is classic and interesting, layers of progressive, so here to record.

1. There is a circle and N lines on a plane, each of these lines intersects with other lines within the circle, assuming that no three lines intersect at a point, how many areas the lines divide into.

2, there are n lines on the plane, ask these polylines can divide the plane into how many blocks? (Known 1->2,2->7)

3, with n-closed curve drawn on the plane, and any two closed curve is at two o'clock, and any three closed curve does not intersect at the same point, ask these closed curves can be divided into the number of areas of the plane.

4, in the rectangular box of 2*n, with n 1*2 dominoes paved square, for example, n = 3 o'clock, for the 2*3 Square, the Domino laying scheme has three kinds, ask for n, the total number of laying scheme.

5, there is a 1*n of a rectangle, with 1*1, 1*2, 1*3 dominoes covered with squares. For example, when n = 3 o'clock is a 1*3 square, there are four kinds of paving methods in which the 1*1,1*2,1*3 dominoes are covered with squares. Q for N, the total number of laying schemes.

6, there is many students in PHT School. One day, the headmaster whose name was Pigheader wanted all students stand in a line. He prescribed that girl can is in a single. In other words, either no girl in the queue or more than one girl stands side by side. The case n=4 (n are the number of children) is like FFFF, FFFM, Mfff, FFMM, MFFM, MMFF, MMMM here F stands for a girl and M stands for a boy. The total number of the queue satisfied the headmaster ' s needs is 7. Can do a program to find the total number of the queue with n children? Too lazy to translate: ~

7, there are rows of n squares, with red, green, blue three primary colors to each grid color, each lattice painted a color, require any adjacent squares can not be the same colour, and the first and the same color of two squares. All the requirements of the coating method.

8, Someone wrote n letters, and N envelopes, if all the letters are loaded in the wrong envelope, how many kinds of possible situations?

———————————————————————— ^^ I am a beautiful split line ^ ^ ————————————————————————

Reference Answer:

1, F (1) = 2; F (n) = f (n-1) + N-pass: F (n) = N (n+1)/2 + 1

2, F (1) = 2; F (n) = f (n-1) + 4 (n-1) + 1-pass: F (n) = 2n^2-n + 1

3, F (1) = 2; F (n) = f (n-1) + 2 (n-1) Pass: F (n) = N^2-n + 2

4, consider the last lattice of paving method, easy to get: f (1) = 1, f (2) = 2; F (n) = f (n-1) + f (n-2), n≥3

5, still consider the last lattice of the paving method, there is: f (1) = 1, f (2) = 2, f (3) = 4; F (n) = f (n-1) + f (n-2) + f (n-3), n≥4

6, according to the last person's gender sub-situation discussion (set F (n) represents the legal queue of n individuals). If it is a boy, standing directly at the end of the queue, there is a case of f (n-1). If it is a girl, then the last two people must be girls, and then classify: if the queue of the former n-2 person is a legitimate queue, append two girls in the queue, there is an F (n-2) situation, in addition, even if the front n-2 person is not a legitimate queue, plus two girls may also be a legitimate queue, and illegal places must be the tail of the queue of length n-2, namely F (n-4) + 1 male + 1 female, so that with two girls to become the legal queue, this situation has f (n-4) species.

In summary, there is a recursive formula: F (1) = 1, f (2) = 2, f (3) = 4, f (4) = 7; F (n) = f (n-1) + f (n-2) + f (n-4), n>4

7, if the front n-1 a lattice has been legally painted, then the last lattice only one coating method, there is f (n-1) method; Another case is that the former n-1 lattice is not legal, then the illegal place must be its tail, that is, the first n-1 lattice and the 1th lattice of the same color, So the last lattice has two kinds of coating methods, so there are 2*f (n-2) method.

In summary, there is a recursive formula: F (1) = 3, f (2) = 6; F (n) = f (n-1) + 2*f (n-2), n>2

8, if the former n-1 letter has been all wrong, just from any one and the first n of the wrong outfit, there is (n-1) *f (n-1) way; In addition if the former N-1 letter and only a letter is not installed wrong (note there is only one, otherwise, hehe:), there (n-1) *f (n-2) way.

In summary, there is a recursive formula: F (1) = 0, f (2) = 1; F (n) = (n-1) *[f (n-1) + F (n-2)]. In addition, it also has a handsome name called the wrong row formula.

PS: The Fibonacci sequence is so useful that you can write about it someday. How to solve its formula by generating function.

Recursive fun problem

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.