This is a creation in Article, where the information may have evolved or changed.
Problem Recurrence:
Xiao Ming just finished the film "39th Steps", when he left the cinema, he counted the number of steps before the auditorium, which happens to be level 39!
Standing before the steps, he suddenly thought of a question:
If I can only go 1 or 2 steps at a step. Take the left foot first, then alternately, the last step is to go to the right foot, that is, a total of even steps. So, how many different ways to go on the 39-step level?
Please take advantage of the computer to help Xiao Ming find the answer.
Recursive solution (Go language implementation)
Package Mainimport ("FMT")/* Recursive core Author: Days of *@i indicates the number of stair climbs * @now represents the current floor * @top represents the total number of stairs *@*count Count */func F (i, now, top int , Count *int) {if now = = Top {//Last must be right foot, 0 left foot, 1 foot right//end when I add 1, so judgment and 0 compare if (i&1) = = 0 {(*count) + +}} else if now < top { F (i+1, now+1, Top, Count) F (i+1, now+2, Top, Count)}}func main () {var count int = 0var Top int = 39//Get input total progression fmt from keyboard. SCANF ("%d", &top) F (0, 0, top, &count) fmt. PRINTLN (count)//Let the screen stay in FMT. SCANF ("%c", &top) fmt. SCANF ("%c", &top)}