def fib(n):
fibList=[1,1]
for i in range(2,n+1):
fibList.append(fibList[i-2]+fibList[i-1)
return fbList[-1]
def fib(n):
if n==0 or n==1:
return 1
else:
return fib(n-1)+fib(n-2)
memo={0:1,1:1}
def fib(n):
if n in memo:
return memo[n]
else:
result=fib(n-1)+fib(n-2)
memo[n]=result
return reslt
data[3,4,5,6,1,2,5]
이웃하지 않는 숫자들의 합의 최댓값은?
def solution(data):
if len(data)==1:
return data[0]
result= [data[0],max(data[0],data[1]) #메모이제이션할 배열 선언
for i in range(2,len(data)):
result.append(max(result[i-1],result[i-2]+data[i])
return result[-1]