알고리즘

BOJ 9095번

Unan 2023. 1. 18. 16:51
반응형
  • DP를 이용하는 기초문제.
N = int(input())

d = [0] * 100000

def calc(x):
    if x == 1:
        return 1 # 1
    elif x == 2:
        return 2 # 1 + 1, 2
    elif x == 3:
        return 4 # 1 + 1 + 1, 1 + 2, 3

    if d[x] != 0:
        return d[x]

    d[x] = calc(x-1) + calc(x-2) + calc(x-3)
    return d[x]

for _ in range(N):
    num = int(input())
    print(calc(num))
  • 백준허브라는 크롬 익스텐션을 사용하니, 백준 문제를 해결하면 레포지토리에 자동업로드 되게 할 수 있었다. 매우 유용한 익스텐션이다.
반응형