1 <? PHP 2 # Step jumping Problem 3 # There are two methods to skip a step: one step or two steps, there are several methods to skip n steps. 4 # If n = 1, there is only one method. n = 2 There are two ways to skip level 1 at a time, skip Level 2 5 at a time # If n> 2, there are two possible situations. The first is the first hop level 1, and the remaining hop method is F (n-1) 6 # The second is the first hop Level 2, so the rest of the hop method is F (n-2), then f (n) = f (n-1) + f (n-2) 7 # so there is a recursive formula 8 # | 1 n = 1 9 # F (n) = <2 n = 210 # | f (n-1) + f (n-2) n> 211 # then the solution to this problem is similar to fabonacci's 12 13 function jump ($ n) {14 if ($ n = 1) return 1; 15 if ($ n = 2) return 2; 16 $ A = 1; 17 $ B = 2 ; 18 $ I = 3; 19 while ($ I <= $ n) {20 $ c = $ A + $ B; 21 $ A = $ B; 22 $ B = $ C; 23 $ I ++; 24} 25 return $ C; 26} 27 28 echo jump (6); 29?>