[SWEA] 3376. 파도반 수열 - Python

SWEA '3376. 파도반 수열' 문제 풀이를 정리했습니다.

2024-11-06조회수 -
PythonAlgorithm

풀이

1 1 1 (1+1) (1+1) (1+(1+1)) (1+(1+(1+1))) (1+(1+(1+(1+1)))) ((1+1)+(1+(1+(1+(1+1))))) ((1+(1+1))+((1+1)+(1+(1+(1+(1+1))))))

수열 나열 후 규칙 찾기 점화식: **d[i] = d[i-1] + d[i-5] **

코드

# 3376
# 파도반 수열
 
T = int(input())
 
for test_case in range(1,T+1):
    n = int(input())
    seq = [1,1,1,2,2]
    if n > 5:
        i = 5
        while i <= n:
            seq.append(seq[i-1]+seq[i-5])
            i += 1
    result = seq[n-1]
    print(f"#{test_case} {result}")

출처: SWEA https://swexpertacademy.com/main/main.do

Comments

© 2026. Kwon In. All rights reserved.