반응형
def iter(n, cache):
if n < 2:
cache[n] = n
return cache[n]
if cache[n] != -1:
return cache[n]
cache[n] = iter(n-1, cache) + iter(n-2, cache)
return cache[n]
def fibonacci(n):
cache = [-1 for _ in range(n+1)]
return iter(n, cache)
if __name__ == '__main__':
n = int(input())
print(fibonacci(n))
반응형