Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the problem of frog jumping steps by python

Shulou Source: shulou.com Published: 2022-05-31 14:05:22 09月27日 Update

In this article, the editor introduces in detail "how to solve the problem of frog jumping steps in python". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to solve the problem of frog jumping steps in python" can help you solve your doubts.

Frogs jump steps # A frog can jump one step at a time, or two steps at a time. Find out the total number of jumping methods for the frog to jump on an n-step step (different order is a different result). #-*-coding:utf-8-*-class Solution: # stupid method: traverse three layers, find all the permutations in each layer, and then remove def jumpFloor (self, number): if number%2==0: min = number//2 else: min = number//2+1 max = number n = 0 for num in range (min) Max+1): for i in range (2**num): K = I temp = 0 for j in range (num): massik-(2*int (kamp 2)) k = int (kmax 2) if masks 0: Temp + = 1 else: temp + = 2 if temp==number: return n # recursively implement def rec_jump (self N): if nameplate 1: return 1 elif nameplate 2: return 2 else: return self.rec_jump (nmur1) + self.rec_jump (nMuth2) # non-recursive implementation, mathematical inference method to achieve f (n) = f (nMul 1) + f (NMAE 2)-- > sum=t1+t2 def lt_jump (self) N): T1 = 1 T2 = 2 if n = 1: return 1 elif n = = 2: return 2 else: for i in range (2LGI n): sum = T1 + T2 T1 = T2 T2 = sum return sum # list implementation def lt_list_jump (self N): res_arr = [1Magazine 2] for i in range (2 N): res_arr.append (res_ arr [I-1] + res_ arr [I-2]) return res_ arr [n-1] if _ _ name__ ='_ _ main__': sl = Solution () print (sl.jumpFloor (15)) print (sl.rec_jump (15)) print (sl.lt_jump (15)) print (sl.lt_list_jump (15)) This article "how to solve the problem of frog jumping steps in python" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Steps frogs questions articles differences content recursion appropriateness sequence methods ideas mathematics new knowledge more order steps knowledge knowledge points articles details Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia OPPO Reno Linux Redmi