C # solve the problem of raising cattle from farmers to the Fibonacci series

Source: Internet
Author: User

A farmer raises a cow. After three years, this ox produces one ox every year. After three years, another ox can be born every year ...... How many cows does a farmer have in 10 years? What about n years?

Here we will talk about the idea of solving this problem. First, you can contact the Fibonacci series. If f (n) is the nth ox, f (n) = f (n-1) + f (n-2) ----> Expression 1-1 means that the number of cattle in the nth year is the number of cattle in the last year. f (n-1) plus the number of cows born this year. How many cows can be born this year? (Ignore the dead ox) is the number of cows in the previous year, that is, f (n-2), because the ox in the previous year is at least 3 years old, that is, expression 1-1. After we set the reproductive age of a ox to m, the calculated expression is f (n) = f (n-1) + f (n-m + 1) ----> Expression 1-2 is the number of cows plus the number of cows in n-1 years plus the number of cows in n-m + 1 years. The following is a slightly complex question. If we add a condition that the ox will die in 8th years, how many cows will there be in the nth annual meeting? For convenience of derivation, here we first set several functions: · f (n), that is, the number of cattle in the nth year · h (n), that is, the number of cattle born in the nth year · g (n) that is, the number of cows that died in the nth year. Here we can first think of an expression: (1) f (n) = f (n-1) + h (n)-g (n) that is, the number of cattle in the nth year is the number of cattle in the nth year + the number of cattle born in the nth year-the number of cattle that died in the nth year, and the second expression is the number of new cattle h (n) (2) h (n) = f (n-2)-g (n-1) that is to say, the number of cattle born in the nth year is the number of cattle in the nth year of N-2 minus the number of cattle dead in n-1 year. Then we can look at the number of cattle that died in the nth year in the third expression: (3) g (n) = h (n-7) indicates that the number of cattle that died in the nth year is the number of cattle born in the nth year. This is a symmetric relationship. The derivation procedure is as follows. (2) is substituted into (1), that is, f (n) = f (n-1) + f (n-2)-g (n-1) -g (n) ----> (4) then substitute the (3) formula into (4), that is, f (n) = f (n-1) + f (n-2) -h (n-8)-h (n-7) -----> (5) then, replace (2) with the h (n-7) of (5) that is, f (n) = f (n-1) + f (n-2)-(h (n-8) + f (n-9) -g (n-8) Here it is not difficult to see (h (n-8) + f (n-9)-g (n-8 )) that is, f (n-8) passes the formula (1 ).
Related Article

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.