[白俊/DP]9095


9095次問題
DPは手帳を使う必要があると言っています
def solution(n):

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

    for i in range(n+2):

        if i+1 <= n:
            count_array[i+1] += count_array[i]
        if i+2 <= n:
            count_array[i+2] += count_array[i]
        if i+3 <= n:
            count_array[i+3] += count_array[i]     
        
    return count_array[n]

n = int(input())
answer = []
for i in range(n):
    answer.append(int(input()))

for num in answer:
    print(solution(num))

  • 配列中に現在indexを加えた方式数を格納
  • 現在index+1、+2、+3の位置値に現在のindexを予め加算