본문 바로가기

Programming [Python]/백준 알고리즘 솔루션

#245 백준 파이썬 [9507] Generations of Tribbles

https://www.acmicpc.net/problem/9507

 

Python Code

def koong(n):
    if n < 2:
        print(1)
    elif n == 2:
        print(2)
    elif n == 3:
        print(4)
    else:
        t1 = t2 = 1
        t3 = 2
        t4 = 4
        for _ in range(n-3):
            t5 = t1 + t2 + t3 + t4
            t1 = t2
            t2 = t3
            t3 = t4
            t4 = t5
        print(t5)


t = int(input())
for _ in range(t):
    n = int(input())
    koong(n)