Recursion of 01python algorithm

Source: Internet
Author: User

Recursive

1 What is recursion?: Based on the value of the existing node and the value of the node after the rule is rolled out

2 Why use recursion: a simple solution to a disciplined event

3 How to use? :

Let's give a classic example:

If 1 pairs of rabbits can produce 1 pairs of rabbits a month, and each pair of rabbits in its 3rd month after birth can produce 1 pairs of rabbits, if starting from 1 pairs of newborn rabbits, 1 years later can reproduce how many rabbits?

def my1 (max):

A, b,c, i= 1,0,0 0

While I<max:
c = c+b
b = A
A = C
Print A+b+c
I+=1

Methods: We can divide the rabbit into 1-month-old, 2-month-old, 3-month-old through the law we know that the 1-month-old rabbit will become the February Big Rabbit next month, and February will become March

Big and March will always accumulate, so the rule is very obvious, March big next month equals itself March rabbit + February Rabbit (Grow Up), and the February Rabbit will become the number of rabbits in January,

The number of January equals the March Bunny (3 months rabbit will give birth to rabbits)

Recursion of 01python algorithm

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.