데이터 구조 및 분석 ch_4_4 Fibonacci Sequence in DP
Jul 25, 2021
»
writing
KAIST 산업및시스템공학과 문일철_ 데이터 구조 및 분석 수업을 참고하여 작성하였습니다
ch_4_4 Fibonacci Sequence in DP
Fibonacci Sequence in DP
1. Fibonacci Sequence in DP - Use a dictionary collection variable type of memoization - Memoization : Storing a fibonacci number for a particular index
def FibonacciDP(n) :
dicFibonacci = {}
dicFibonacci[0] = 0
dicFibonacci[1] = 1
for itr in range(2, n+1):
dicFibonacci[itr] = dicFibonacci[itr-1] + dicFibonacci[itr-2]
return dicFibonacci[n]
for itr in range(0,10) :
print(FibonacciDP(itr))
# 0
# 1
# 1
# 2
# 3
# 5
# 8
# 13
# 21
# 34