25 steps, each step or two, ask the maximum number of ways to go
Source: Internet
Author: User
Analysis: A total of 25 steps, each step of a total of two, go first level, or go to two level. In two cases: if the first time to go two level, then there are 25-2 = 23 steps to go. And then ask for the remaining 23 steps to the total number of walking method. If the first step, then there are 25-1 = 24 steps to go, so the total number of steps 25 ladder, is equal to climb the 23 steps Total Method + climbed the 24 steps of the total number of methods. and 23 pole can be divided into (23-1), (23-2) level ladder. By analogy, this is a typical recursive type. We can easily calculate all the times when there are 1 and 2 steps: 1 and 2 respectively. The function of the total number of methods is calculated as follows:
---------------------------------getnum ()---------------------------------------------public int getnum (int i) { int r=0; if (i>2) {num=getnum (i-1) +getnum (i-2); return num; else if (i==1) {r=1; else if (i==2) {r=2; } return R; ---------------------------------------------------------------------------------------the test program is written in Java. Run use command: Java Stair 25
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