Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Fibonacci Number

  Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula:

\begin{equation*}
fib(n)= \left \{
\begin{array}{ll}
1　         &   (n = 0)          \\
1　         &  (n = 1) \\
fib(n - 1) + fib(n - 2)  & \\
\end{array}
\right.
\end{equation*}

Input

  An integer $n$ is given.

output

  Print the $n$-th fibonacci number in a line.

Constraints

$0 \leq n \leq 44$

Sample Input 1

3

Sample Output 1

3



Sample input:
3


Sample output:
3

Submission status: Accepted

Solution code:
def Fibonacci(n):
    if n == 0 or n == 1:
        dic[n] = 1
    if n in dic.keys():
        return dic[n]
    dic[n] = Fibonacci(n-1) + Fibonacci(n-2)
    return dic[n]

a = int(input())
dic ={}
print(Fibonacci(a))

Submission status: Accepted

Solution code:
def fibonacci(n):
    a, b = 1, 0
    for _ in range(0, n):
        a, b = b, a + b
    return b

n=int(input())
n+=1
print(fibonacci(n))

Submission status: Accepted

Solution code:
n=int(input())

a=[1]*45


def fib(n):
    if n==0 or n==1:
        return 1
    else:
        if a[n]==1:
            a[n]=fib(n-1)+fib(n-2)
            
        return a[n]
           
print(fib(n))

Submission status: Accepted

Solution code:
n = int(input())
memo = [None]*(n+1)

def Fib(n):
    if n==0 or n==1:
        return 1
    elif memo[n]:
        return memo[n]
    else:
        r=Fib(n-1)+Fib(n-2)
        memo[n]=r
        return r
print(Fib(n))

Submission status: Accepted

Solution code:
n=int(input())
fib = [1,1]

for i in range(2,n+1):
    fib.append(fib[i-1]+fib[i-2])
    
print(fib.pop())

Submission status: Accepted

Solution code:
n = int(input())
a = b = 1
for i in range(n):
    a,b = b,a+b
print(a)

Submission status: Accepted

Solution code:
n=int(input())
def Fib(n):
    a,b=0,1
    for i in range(n):
        a,b=b,a+b
    return b
print(Fib(n))

Submission status: Accepted

Solution code:
n = int(input())

A = [1]*(n+1)

for i in range(2, n+1):
    A[i] = A[i-1] + A[i-2]
    
print(A[-1])

Submission status: Accepted

Solution code:
n = int(input())
arr = [1, 1]
for i in range(2, 45):
    arr.append(arr[i - 1] + arr[i - 2])
print(arr[n])

Submission status: Accepted

Solution code:
n = int(input())

num = [-1] * 100


def fibonacci(n):
    if n == 0:
        num[0] = 1
    elif n == 1:
        num[1] = 1

    if num[n] == -1:
        num[n] = fibonacci(n - 1) + fibonacci(n - 2)

    return num[n]


print(fibonacci(n))

Submission status: Accepted

Solution code:
n = int(input())

def fb(num):
    a, b = 1, 0
    for i in range(num):
        a, b = a + b, a
    return b

print(fb(n+1))

Submission status: Accepted

Solution code:
def solve(n):
    dp=[1]*(n+1)
    for i in range(2,n+1):
        dp[i]=dp[i-1]+dp[i-2]
    return dp[n]
n=int(input())
print(solve(n))

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    A = [1, 1]
    for i in range(1, 45):
        A.append(A[i - 1] + A[i])
    print(A[n])


resolve()

Submission status: Accepted

Solution code:
def main():
    def fib(n):
        a = 1
        b = 1
        if n == 0:
            return a
        elif n == 1:
            return b
        else:
            for i in range(n-1):
                a, b = b, a + b
            return b
    
    n = int(input())
    print(fib(n))
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    N = int(sys.stdin.readline())
    L = [0 for i in range(45)]
    L[0], L[1] = 1, 1
    for i in range(2, 45):
        L[i] = L[i-1] + L[i-2]
    #print(L)
    print(L[N])
    



if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(range(n+1))
a[0]=1
i=2
while i<=n:
    a[i]=a[i-1]+a[i-2]
    i+=1
print(a[n])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n=int(input())
fib=[1]*50
for i in range(2,n+1):
    fib[i]=fib[i-1]+fib[i-2]
    
print(fib[n])

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    if N <= 1:
        print(1)
        return
    fib = [0]*(N+1)
    fib[0], fib[1] = 1, 1
    for i in range(2, N+1):
        fib[i] = fib[i-1] + fib[i-2]
    print(fib[N])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
N =[1, 1, 2]
if n < 3:
    print(N[n])
else:
    i = 2
    while i < n:
        n0, n1, n2 = N
        N[2] = n1 + n2
        N[1] = n2
        N[0] = n1
        i += 1
    print(N[2])

Submission status: Accepted

Solution code:
n = int(input())
fib = [1, 1]
for i in range(2, n+1):
  fib.append(fib[i-1] + fib[i-2])
print(fib.pop())

Submission status: Accepted

Solution code:
n=int(input())
fib=[0 for i in range(n+1)]
fib[0]=1
fib[1]=1
for i in range(2,n+1):
    fib[i]=fib[i-1]+fib[i-2]
print(fib[n])

Submission status: Accepted

Solution code:
n = int(input())
dp = [0 for _ in range(46)]
dp[0] = 1
dp[1] = 1
for i in range(2, 46):
	dp[i] = dp[i-1] + dp[i-2]
print(dp[n])

Submission status: Accepted

Solution code:
n = int(input())
a = 1
b = 1
c = []
c.append(a)     
c.append(b)
#print(c)
for i in range(n):
        c.append(a+b) 
        #print(c)
        d = b
        b += a
        a = d
print(c[n])

Submission status: Accepted

Solution code:
#40 フィボナッチ数列 - Time Limit Exceeded

n = int(input())
a = 1
b = 1
c = []
c.append(a)     #リストcの最後にaの値を付加
c.append(b)     #リストcの最後にbの値を付加
       
for i in range(n):
        c.append(a+b)   #リストcの最後にa+bの値を付加
        d = b           
        b += a
        a = d
print(c[n])

Submission status: Accepted

Solution code:
n = int(input())

F = [0]*50
F[0] = 1
F[1] = 1
if n== 0 or n==1:
    print(F[n])
else:
    for i in range(2,n+1):
        F[i] = F[i-1]+ F[i-2]
    print(F[n])

Submission status: Accepted

Solution code:
n=int(input())
x=0
y=1
if n==0 or n==1:
    print(1)
else:
    for i in range(n):
        x,y=y,x+y
        i+=1
    print(y)

Submission status: Accepted

Solution code:
def solve(n):
    if n <= 1:
        print(1)
        return

    a, b = 1, 1
    for _ in range(2, n + 1):
        c = a + b
        b = a
        a = c
    print(c)

if __name__ == "__main__":
    n = int(input())
    solve(n)

Submission status: Accepted

Solution code:
# ALDS_10_A - フィボナッチ数

n = int(input())

dp = [0] * (n + 1)

for i in range(n + 1):
    if (i == 0) or (i == 1):
        dp[i] = 1
    else:
        dp[i] = dp[i - 1] + dp[i - 2]

print(dp[-1])
# print(dp)

Submission status: Accepted

Solution code:
n = int(input())
dp = [1, 1]
for i in range(2, n + 1):
    dp = [dp[-1], dp[-2] + dp[-1]]
print(dp[-1])

Submission status: Accepted

Solution code:
def fibonacci(N, dp):
    if dp[N] != 0:
        return dp[N]
    if N == 1 or N == 0:
        dp[N] = 1
    else:
        dp[N] = fibonacci(N - 1, dp) + fibonacci(N - 2, dp)
    return dp[N]


def main():
    N = int(input())
    dp = [0] * (N + 1)
    print(fibonacci(N, dp))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=b=1
while n:
    a,b=b,a+b
    n-=1
print(a)

Submission status: Accepted

Solution code:
N = int(input())

memo = []

memo = [1,1] + [0] * (N - 1)

def f(n):
    if memo[n] == 0:
        memo[n] = f(n-1) + f(n-2)
        return(memo[n])
    if memo[n] != 0:
        return(memo[n])

print(f(N))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# https://qiita.com/e869120/items/eb50fdaece12be418faa
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A&lang=ja


def main():
    n = int(input().strip())
    print(fib(n))


def fib(n):
    dp = [1] * (n + 1)
    for i in range(2, n + 1):
        dp[i] = dp[i - 1] + dp[i - 2]
    return dp[n]


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
l = [0 for _ in range(10**4)]
def fib(n):
    if n==0:
      l[0]=1
      return 1
    if n==1:
      l[1]=1
      return 1
    if l[n]!=0:
      return l[n]
    else:
      l[n]=fib(n-1)+fib(n-2)
      return fib(n-1)+fib(n-2)
    
print(fib(n))

Submission status: Accepted

Solution code:
n = int(input())
def fib(i):
    if i<=1: return 1
    else: 
     a=0
     b=1
     for i in range(n+1):
      c=b+a
      b=a
      a=c
     return c
print(fib(n))

Submission status: Accepted

Solution code:
n=int(input())

dp=[1,1]
def fib(n):
    if n==0 and n==1:
        return dp[n]
    for i in range(2,n+1):
        dp.append(dp[i-1]+dp[i-2])
    return dp[n]
print(fib(n))

Submission status: Accepted

Solution code:
n = int(input())
fib = [0] * (n + 1)
fib[0] = 1
if n > 0: fib[1] = 1
for i in range(2, n+1):
    fib[i] = fib[i-1] + fib[i-2]
print(fib[n])

Submission status: Accepted

Solution code:
n = int(input())
DP = [None] * (n + 1)  # 計算結果を保存する配列
DP[0] = 1  # 定義より
DP[1] = 1  # 定義より

def fib(n):
    # フィボナッチ数を2からnまで順に求めていく
    for i in range(2, n + 1):
        DP[i] = DP[i-1] + DP[i-2]
    return DP[n]

print(fib(n))

Submission status: Accepted

Solution code:
def fib(n):
    a = 1
    b = 1
    if n == 0:
        print(a)
    elif n == 1:
        print(b)
    else:
        for i in range(n-1):
            c = a + b
            a , b = b , c
        print(c)

n = int(input())
fib(n)

Submission status: Accepted

Solution code:

f = [-1]*45
f[0]=1
f[1]=1

def fib(i):
    global f

    if i<=1:
        return f[i]
    if f[i] == -1:
        f[i] = fib(i-1)+fib(i-2)
    return f[i]

n=int(input())
print(fib(n))

Submission status: Accepted

Solution code:
n = int(input())
dp = [1, 1]
if n >1:
  for i in range(2, n + 1):
    dp.append(dp[i - 1] + dp[i - 2])
print(dp[n])

Submission status: Accepted

Solution code:
n=int(input())

fib=[0]*(n+1)
fib[0]=1
fib[1]=1

for ni in range(2,n+1):
    fib[ni]=fib[ni-1]+fib[ni-2]
    
print(fib[n])

Submission status: Accepted

Solution code:
def fina(n, fina_list):

    if n <= 1:
        fina_list[n] = 1
        return fina_list[n]
    elif fina_list[n]:
        return fina_list[n]
    else:
        fina_list[n] = fina(n-1, fina_list) + fina(n-2, fina_list)
        return fina_list[n]


n = int(input())
fina_list = [None]*(n + 1)
print(fina(n, fina_list))

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

n = int(input())
dp = [0]*(1000001)
dp[0] = 1
dp[1] = 1
for i in range(2,n+1):
    dp[i] = dp[i-1] + dp[i-2]
print(dp[n])

Submission status: Accepted

Solution code:
N = int(input())

dp = [1] * (N + 1)

for n in range(2, N + 1):
    dp[n] = dp[n - 1] + dp[n - 2]

print(dp[N])

Submission status: Accepted

Solution code:
N=int(input())
dp=[0]*(N+1)
dp[0]=1
dp[1]=1
for i in range(2,N+1):
    dp[i]=dp[i-1]+dp[i-2]
ans=dp[N]
print(ans)

Submission status: Accepted

Solution code:
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
    if n==0 or n==1:
        return 1
    else:
        return fib(n-1)+fib(n-2)
n=int(input())
print(fib(n))

Submission status: Accepted

Solution code:
# ALDS1_10_A.py
N = int(input())
fib_list = [0]*(N+1)
def fib(n):
    if n<=1:
        fib_list[n] = 1
    else:
        if fib_list[n] == 0:
            fib_list[n] = fib(n-1) + fib(n-2)
    return fib_list[n]
fib(N)
print(fib_list[N])

Submission status: Accepted

Solution code:
def f(n):
    f=[1,1]
    for i in range(2,n):
        f.append(f[i-2]+f[i-1])
    return f[n-1]

n=int(input())        
print(f(n+1))

Submission status: Accepted

Solution code:
def fib(n):
    x=[1,1]
    for i in range(n+1):
        y=x[i]+x[i+1]
        x.append(y)
    print(x[n])
    
a=int(input())
fib(a)

Submission status: Accepted

Solution code:
n = int(input())
a0 = 1
a1 = 1

#print(a0, a1, end='')
if n == 0 or n == 1:
    a2 = 1

else:
    for i in range(n-1):
        a2 = a0 + a1
        a0 = a1
        a1 = a2
    #print('',a2,end='')
print(a2)

Submission status: Accepted

Solution code:
n=int(input())
a=[1,1]
def fib(n):
    if n <= 1:
        return a[n]
    for i in range(2,n+1):
        a.append(a[i-1]+a[i-2])
    return a[n]
print(fib(n))

Submission status: Accepted

Solution code:
def fib(n,memo={}):
    if n == 0:
        return 1
    elif n == 1:
        return 1
    elif n in memo:
        return memo[n]
        
    else:
        memo[n]=fib(n-1,memo)+fib(n-2,memo)
        return memo[n]
a=int(input())
print(fib(a))

Submission status: Accepted

Solution code:
n = int(input())
def fib(x):
    lst=[1,1]
    for i in range(x-1):
        z = len(lst)
        y = int(lst[z-2])+int(lst[z-1])
        lst.append(y)
    print(lst[x])
fib(n)

Submission status: Accepted

Solution code:
n = int(input())

def fib(n):
    dp = [0] * (n+1)
    dp[0] = 1
    dp[1] = 1

    def fib_sub(n):
        if dp[n] != 0:
            return dp[n]

        fibn1 = fib_sub(n-1)
        fibn2 = fib_sub(n-2)
        dp[n-1] = fibn1
        dp[n-2] = fibn2
        return fibn1 + fibn2

    return fib_sub(n)
print(fib(n))

Submission status: Accepted

Solution code:
n = int(input())

F = [0]*(n+1)
if n == 0:
    print(1)
elif n==1:
    print(1)
elif n > 1:
    F[0] = 1
    F[1] = 1

    for i in range(2,n+1):
        F[i] = F[i-1] + F[i-2]

    print(F[-1])

Submission status: Accepted

Solution code:
n = int(input())

dp = [0]*(45)
dp[0] = 1
dp[1] = 1
def fib(i):
    j = 2
    while j <= i:
        if j >= 2:
            dp[j] = dp[j-1] + dp[j-2]
        j += 1

fib(n)
print(dp[n])

Submission status: Accepted

Solution code:
import sys
if __name__ == "__main__":
    n = int(input())
    if n == 0 or n == 1:
        print(1)
        sys.exit(0)
    dp = [0] * (n + 1)
    dp[0] = 1
    dp[1] = 1
    for i in range(2, n + 1):
        dp[i] = dp[i - 1] + dp[i - 2]
    print(dp[n])

Submission status: Accepted

Solution code:
F = [0 for i in range(50)]
F[0] = 1
F[1] = 1

def fib(n) :
    if n == 0 or n == 1:
        F[n] = 1
        return F[n]
    else:
        if F[n] == 0:
            F[n] = fib(n-1) + fib(n-2)
            return F[n]
        else:
            return F[n]
n = int(input())
print(fib(n))

Submission status: Accepted

Solution code:
n = int(input())
dp = [1] * (50)
for i in range(n):
    dp[i + 2] = dp[i + 1] + dp[i]

print(dp[n])

Submission status: Accepted

Solution code:
n = int(input())

fib = [-1] * (n+1)
fib[0] = 1
fib[1] = 1
for i in range(2,n+1):
    fib[i] = fib[i-1] + fib[i-2]

print(fib[n])

Submission status: Accepted

Solution code:
def fibonacci_dp(n,lf):
    if n == 0 or n == 1:
        return lf[n]
    if n < len(lf):
        return lf[n]
    lf.insert(n,fibonacci_dp(n-2,lf) + fibonacci_dp(n-1,lf))
    return lf[n]

if __name__ == "__main__":
    n = int(input())
    lf = [1,1,]
    print(fibonacci_dp(n,lf))

Submission status: Accepted

Solution code:
n=int(input())

fib=[1,1]
for i in range(2,n+1):
    a=fib[i-1]+fib[i-2]
    fib.append(a)

print(fib[n])

Submission status: Accepted

Solution code:
n = int(input())
n1 = 1
n2 = 1
result = 0
if n < 2:
    result = 1
else:
    for i in range(n-1):
        result = n1 + n2
        n2 = n1
        n1 = result
print(result)

Submission status: Accepted

Solution code:
# coding: utf-8
# 40

n = int(input())
a = int(0)
b = int(1)

if n==1:
    A = b
elif n==2:
    A = 2
else:
    for i in range(n):
        a,b = b,a+b
        A = b

print(A)

Submission status: Accepted

Solution code:
from functools import lru_cache

@lru_cache()
def fib(n:int):
    if n == 0 or n == 1:
        return 1
    else:
        return fib(n-1) + fib(n-2)

n = int(input())
print(fib(n))

Submission status: Accepted

Solution code:
a=[0]*45
a[0]=1
a[1]=1

for i in range(2,45):
    a[i]=a[i-1]+a[i-2]

n=int(input())
print(a[n])

Submission status: Accepted

Solution code:

fibo = [0] * 45
N = int(input())
fibo[0] = 1
fibo[1] = 1

for i in range(2,N+1):
    fibo[i] = fibo[i-1]+fibo[i-2]

print(fibo[N])
# N = int(input())　再帰のみ
# def fibo(n):
#     if n == 0 or n == 1:
#         return 1
#     return fibo(n-1)+fibo(n-2)
# print(fibo(N))
# N = int(input()) メモ化再帰　5596KB 635B
# def fibo(n):
#     return fib2(1,1,n-1)
# def fib2(a,b,c):
#     if c < 1:
#         return a
#     return fib2(a+b,a,c-1)
# print(fibo(N))

Submission status: Accepted

Solution code:
n=int(input())
x, y=0, 1
for i in range(1, n+1):
    x, y=y, x+y
print(y)

Submission status: Accepted

Solution code:
n = int(input())
fib = [1, 1]
for i in range(2, n+1):
    fib.append(fib[i-1] + fib[i-2])
print(fib[n])

Submission status: Accepted

Solution code:
n = int(input())
a = [1, 1]
for i in range(2, n+1):
    a.append(a[i-1] + a[i-2])
print(a[n])

Submission status: Accepted

Solution code:
memo = {}


def fib(n):
    """
    :param n: non-negative integer
    :return: n-th fibonacci number
    """
    if n == 0 or n == 1:
        return 1

    try:
        return memo[n]
    except KeyError:
        pass

    res = fib(n-1) + fib(n-2)
    memo[n] = res

    return res


n = int(input())
print(fib(n))

Submission status: Accepted

Solution code:
x=int(input())
if x == 0 or x == 1 : print("1")
else : 
    i=0
    b=1
    c=1
    while i<(x-1) :
        d=b+c
        c=b
        b=d
        i=i+1
        
    print(b)

Submission status: Accepted

Solution code:
n = int(input())

fib = []
for i in range(n+1):
    if i <=1 :
        fib.append(1)
    if i > 1 :
        fib.append( fib[i-2] + fib[i-1] )

print(fib[n])

Submission status: Accepted

Solution code:
#1_10_A
n = int(input())
MEMO = [None] * (n + 1)

def Fib(i):
    if i == 0 or i == 1:
        return 1
        
    if MEMO[i]:
        return MEMO[i]
    
    r =  Fib(i-1) + Fib(i-2)
    MEMO[i] = r
    return r
     
print(Fib(n))

Submission status: Accepted

Solution code:
n=int(input())
a=b=1
while range(n):
    a,b=b,a+b
    n-=1
print(a)

Submission status: Accepted

Solution code:
n = int(input())
fib = [1,1]

if n>=2:
    for i in range(2,n+1):
        fib.append(fib[i-1]+fib[i-2])
        
print(fib[n])

Submission status: Accepted

Solution code:
n = int(input())
fib_b = [1,1]
if n > 1:
    for i in range(2,n+1):
        fib_b.append(fib_b[i-1]+fib_b[i-2])

print(fib_b[n])

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A&lang=ja
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    n = int(readline())

    dp = [0] * (n+1)
    dp[0] = 1
    dp[1] = 1

    for i in range(2,n+1):
        dp[i] = dp[i-1] + dp[i-2]

    print(dp[n])    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def fibn(n):
    fib = [1,1]
    for i in range(2,n+1):
        fib.append(fib[i-2] + fib[i-1])
    return fib[n]
    
x = int(input())
print(fibn(x))

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    dp=[0]*(n+1)
    for i in range(n+1):
        if i==0 or i==1:
            dp[i]=1
        else:
            dp[i]=dp[i-1]+dp[i-2]

    print(dp[n])
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())

a1=1
a=1

i=1
while i<n:
    a1,a=a,a1+a
    i+=1


print(a)

Submission status: Accepted

Solution code:
n = int(input())

def fib(i):
    if i<=1:
        return 1
    
    else:
        a, b = 0, 1
        for i in range(n+1):
            c = b + a
            b = a
            a = c
        return c

print(fib(n))

Submission status: Accepted

Solution code:
n = int(input())
memo = [-1]*(n+1)
memo[0] = 1
memo[1] = 1

def fib(n):
    if memo[n] != -1:
        return memo[n]
    else:
        ans = fib(n-1)+fib(n-2)
        memo[n] = ans
        return ans

print(fib(n))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

def fibo(n, memo = {}):
   if n == 0 or n == 1:
      return 1
   elif n in memo:
      return memo[n]
   else:
      memo[n] = fibo(n - 1, memo) + fibo(n - 2, memo)
      return memo[n]

n = int(input())
print(fibo(n))

Submission status: Accepted

Solution code:
n=int(input())
MAX_N=n
MEMO = [None] * (MAX_N + 1)
def f(n):
    if n==0:
        return 1
    if n==1:
        return 1
    if MEMO[n]:
        return MEMO[n]
    r=f(n-1)+f(n-2)
    MEMO[n]=r
    return r
    
print(f(n))

Submission status: Accepted

Solution code:
n = int(input())

fib = [1, 1]
for i in range(2, n+1):
    fib.append(fib[i-1] + fib[i-2])

print(fib[n])

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

def solve():
    import sys

    N = int(sys.stdin.readline())

    dp = [None]*45
    dp[0], dp[1] = 1, 1

    def fib(n):
        if dp[n] is not None:
            return dp[n]
        dp[n] = fib(n-1) + fib(n-2)
        return dp[n]

    print(fib(N))


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
fib = [0 for i in range(45)]
fib[0] = 1
fib[1] = 1
for i in range(2, 45):
  fib[i] = fib[i - 1] + fib[i - 2]
a = int(input())
print(fib[a])

Submission status: Accepted

Solution code:
n = int(input())

num = [1,1]

for i in range(2,45):
  f = num[i - 1] + num[i - 2]
  num.append(f)
  
print(num[n])

Submission status: Accepted

Solution code:
n = int(input())
dp = [0]*(n+1)
dp[0] = dp[1] = 1
for i in range(2,n+1):
    dp[i] = dp[i-1] + dp[i-2]
print(dp[n])

Submission status: Accepted

Solution code:
MAX_N = 44
dp = [None] * (MAX_N + 1)
dp[0] = 1
dp[1] = 1

def fib(n):
    for i in range(2, n+1):
        dp[i] = dp[i-1] + dp[i-2]
    
    return dp[n]

n = int(input())
print(fib(n))

Submission status: Accepted

Solution code:
from functools import lru_cache

@lru_cache(maxsize=None)
def Fib(n) :
    if n == 0 :
        return 1
    elif n == 1 :
        return 1
    else :
        return Fib(n-1) + Fib(n-2)

N = int(input())
print(Fib(N))

Submission status: Accepted

Solution code:
N = int(input())

def solve(N):
    fib = [1]*(N+1)
    for i in range(2,N+1):
        fib[i] = fib[i-1] + fib[i-2]
    ans = fib[N]
    return ans
print(solve(N))

Submission status: Accepted

Solution code:
n = int(input())

def fib(n):
 if(n==0): return 1
 elif(n==1): return 1
 elif(n>1):
   a,b = 1,1
   for i in range(n-1):
     a,b = b,a+b
   return b

print(fib(n))

Submission status: Accepted

Solution code:
def fib(n):

    if n ==0 or n ==1:
        return 1
    dp = [0] * (n+1)
    dp[0] = 1
    dp[1] = 1
    for i in range(2,n+1):
        dp[i] += dp[i-1] + dp[i- 2]
    return dp[n ]
# if __name__ == '__main__':
n=int(input())
print(fib(n))

Submission status: Accepted

Solution code:
y=[1,1]
n=int(input())
for i in range(0,n):
    a=y[i]+y[i+1]
    y.append(a)
print(y[n])

Submission status: Accepted

Solution code:
N = int(input())
dp = [0] * (N+1)
dp[0] = 1
dp[1] = 1
for i in range(2,N+1):
    dp[i] = dp[i-1] + dp[i-2]

print(dp[N])

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline().strip())

fib = [0] * (n+1)
fib[0] = 1
fib[1] = 1

for i in range(2, n+1):
    fib[i] = fib[i-1] + fib[i-2]
print(fib[n])

Submission status: Accepted

Solution code:
N = int(input())
dp = [None] * (N + 1)

def fib(n):
    if dp[n] != None:
        return dp[n]
    if n == 0 or n == 1:
        dp[n] = 1
    else:
        dp[n] = fib(n - 2) + fib(n - 1)
    return dp[n]

print(fib(N))

Submission status: Accepted

Solution code:
n = int(input())
F = [0] * 45

def fib(n) :
    if n == 0 or n == 1 :
        return 1
    else :
        if F[n] != 0 :
            return F[n]
        else :
            F[n] = fib(n - 1) + fib(n - 2)
            return F[n]
        
print(fib(n))

Submission status: Accepted

Solution code:
def fibonacci(n, l):
  if n <= 1:
    l[n] = 1
    return l[n]
  elif l[n] != 0:
    return l[n]
  else:
    l[n] = fibonacci(n-1, l) + fibonacci(n-2, l)
    return l[n]


n = int(input())
l = [0] * (n+1)
print(fibonacci(n, l))

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*(N+1)
if N == 0 or N == 1:
    print(1)
else:
    A[0] = 1
    A[1] = 1
    for i in range(2, N+1):
        A[i] = A[i-1] + A[i-2]
    print(A[N])

Submission status: Accepted

Solution code:
n = int(input())
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
for i in range(2, n + 1):
    dp[i] = dp[i - 1] + dp[i - 2]
print(dp[n])

Submission status: Accepted

Solution code:
import sys
n = int(input())
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
if n == 0:
    print(1)
    sys.exit()
elif n == 1:
    print(1)
    sys.exit()

for i in range(2, n+1):
    dp[i] = dp[i-1] + dp[i-2]

print(dp[n])

Submission status: Accepted

Solution code:
n = int(input())

# 動的計画法
def fibonacci(n):
    F = [0]*(n+1)
    F[0] = 1
    F[1] = 1
    for i in range(2, n+1):
        F[i] = F[i-2] + F[i-1]
    return F

f = fibonacci(n)
print(f[n])

Submission status: Accepted

Solution code:
n = int(input())
dp = [0]*(n+1)
for i in range(n+1):
    if i == 0:
        dp[i] = 1
    elif i == 1:
        dp[i] = 1
    else:
        dp[i] = dp[i-1] + dp[i-2]
print(dp[n])

Submission status: Accepted

Solution code:
n = int(input())
dp = [1] * (n+1)

for j in range(n-1):
    dp[j+2] = dp[j+1] + dp[j]
print(dp[n])

Submission status: Accepted

Solution code:
n = int(input())

def fib_loop(n):
	F = [-1] * (n + 1)
	F[0], F[1] = 1, 1
	for i in range(2, n + 1):
		F[i] = F[i - 1] + F[i - 2]
	return F[n]

print(fib_loop(n))

Submission status: Accepted

Solution code:
n = int(input())
fib = [0]*45
fib[0] = 1
fib[1] = 1
for i in range(2,45):
    fib[i] = fib[i-1] + fib[i-2]
print(fib[n])

Submission status: Accepted

Solution code:
N = int(input())

memo = [-1]*500

def fibo(x):
    if memo[x] != -1:
        return memo[x]
    
    if x == 0 or x == 1:
        ans=1
        memo[x] = ans
        return ans
    
    ans = fibo(x-1) + fibo(x-2)
    memo[x] = ans
    return ans

print(fibo(N))

Submission status: Accepted

Solution code:
N = int(input())

DP = [0 for _ in range(N + 1)]
DP[0] = 1
DP[1] = 1

for i in range(2, N + 1):
    DP[i] = DP[i - 1] + DP[i - 2]

print(DP[N])

Submission status: Accepted

Solution code:
fib = [1]*100

for i in range(2,100):
    fib[i] = fib[i-1] + fib[i-2]
    
print(fib[int(input())])

Submission status: Accepted

Solution code:
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())

fib = [1]*50

for i in range(N+2):
    fib[i+2] = fib[i] + fib[i+1]

print(fib[i-1])

Submission status: Accepted

Solution code:
inf = 10**9+7
mod = 10**9+7
n = int(input())
dp = [1 for i in range(n+1)]
for i in range(2,n+1):
    dp[i] = dp[i-2] + dp[i-1]
print(dp[n])

Submission status: Accepted

Solution code:
n=int(input())
DP=[0]*45
DP[0],DP[1]=1,1
for i in range(2,45):
    DP[i]=DP[i-1]+DP[i-2]
print(DP[n])

Submission status: Accepted

Solution code:
n = int(input())
fib = [1]*45
for i in range(2,n+1):
  fib[i] = fib[i-1]+fib[i-2]
print(fib[n])

Submission status: Accepted

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()

m = [-1] * (n+1)
m[0] = 1
m[1] = 1

def fib(n):
    if m[n] != -1:
        return m[n]
    
    ans = fib(n-1) + fib(n-2)
    m[n] = ans
    return ans

print(fib(n))

Submission status: Accepted

Solution code:
n = int(input())

from functools import lru_cache
@lru_cache(maxsize=None)
def fibo(n: int):
    if n == 0 or n == 1:
        return 1
    return fibo(n-1) + fibo(n-2)

print(fibo(n))

Submission status: Accepted

Solution code:
# def fibb(n):
#     if n == 1 or n == 2:
#         return 1
#     else:
#         return fibb(n-1)+fibb(n-2)

n = int(input())
fibb = [0]*45
fibb[0:2] = [1,1]
for i in range(2,45):
    fibb[i] = fibb[i-1] + fibb[i-2]
print(fibb[n])

Submission status: Accepted

Solution code:
n = int(input())
dp = [0]*50
dp[0] = 1
dp[1] = 1
for i in range(2,46):
    dp[i] = dp[i-1] + dp[i-2]

print(dp[n])

Submission status: Accepted

Solution code:
n = int(input())

table = [0] * 45

table[0] = 1
table[1] = 1
for i in range(2,45):
    table[i] = table[i-1]+table[i-2]

print(table[n])

Submission status: Accepted

Solution code:
n = int(input())


dps = [0 for _ in range(n + 1)]

dps[0] = 1
dps[1] = 1

for i in range(2, n + 1):
    dps[i] = dps[i - 2] + dps[i - 1]

print(dps[n])

Submission status: Accepted

Solution code:
n = int(input())

DP = [0 for _ in range(n+1)]
DP[0] = 1
DP[1] = 1

for i in range(2, n+1):
    DP[i] = DP[i-1]+DP[i-2]
print(DP[n])

Submission status: Accepted

Solution code:
def fb(num):
    a, b = 1, 0
    for _ in range(num):
        a, b = a + b, a
    return b

n = int(input())
print(fb(n+1))

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    n = int(input())

    fib = [0]*(n+1)
    fib[0] = 1
    fib[1] = 1
    for i in range(2, n+1):
        fib[i] = fib[i-1]+fib[i-2]

    print(fib[n])

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
fib = [0]*(n+1)
fib[0] = 1
fib[1] = 1
for i in range(2, n+1):
    fib[i] = fib[i-1] + fib[i-2]

print(fib[n])

Submission status: Accepted

Solution code:
n = int(input())
fib = [0] * (n+1)
fib[0] = 1
fib[1] = 1
for i in range(2, n+1):
  fib[i] = fib[i-1] + fib[i-2]
print(fib[n])

Submission status: Accepted

Solution code:
n = int(input())


def fibonacci(n):
    a,b = 1,1
    if n == 0 or n == 1:
        return 1

    else:
        for i in range(n-1):
            a,b = b,a+b
        
        return b

print(fibonacci(n))

Submission status: Accepted

Solution code:
n = int(input())

fibs = [0 for _ in range(n+1)]
# checks = [False for _ in range(n+1)]

def fib(k):
    for i in range(k+1):
        if i == 0:
            fibs[i] = 1
        elif i == 1:
            fibs[i] = 1
        else:
            fibs[i] = fibs[i-1] + fibs[i-2]
    return fibs[k]

print(fib(n))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: print('Yes' if b else 'No')
YESNO=lambda b: print('YES' if b else 'NO')

def main():
    @lru_cache()
    def fib(n):
        if n==0 or n==1:
            return 1
        return fib(n-1)+fib(n-2)
    print(fib(int(input())))
        

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#DPによるフィボナッチ数列
n = int(input())

dp = [-1] * (n+1) #DPテーブルの用意

dp[0] = 1
dp[1] = 1#初期値設定

for i in range(2, n+1):
    dp[i] = dp[i-1] + dp[i-2]

print(dp[n])

Submission status: Accepted

Solution code:
n=int(input())
f=[0]*(n+1)
def fib(n,f):
	if n==0 or n==1:
		return 1
	else:
		if f[n]!=0:
			return f[n]
		else:
			f[n]=fib(n-1,f)+fib(n-2,f)
			return f[n]
print(fib(n,f))

Submission status: Accepted

Solution code:
n = int(input())
fib = [1]*(n+1)
for i in range(2,n+1): fib[i] = fib[i-1] + fib[i-2]
print(fib[n])

Submission status: Accepted

Solution code:
N = int(input())
fib = [None] * (N+1)
fib[0] = 1
fib[1] = 1
for i in range(2,N+1):
  fib[i] = fib[i-1] + fib[i-2]
print(fib[N])