9461-s3 성공

This commit is contained in:
sm4640
2026-03-27 10:30:14 +09:00
parent 8f84a61a23
commit 87e7ad2fcb

View File

@@ -0,0 +1,32 @@
# 파도반 수열
import sys
input = sys.stdin.readline
def solution():
t = int(input().rstrip())
dp = [0] * 102
dp[:5] = [1,1,1,2,2]
for i in range(5, 102):
dp[i] = dp[i-5]+dp[i-1]
for _ in range(t):
n = int(input().rstrip())
print(dp[n-1])
return
solution()
"""
걸린 시간: 17분
시간 복잡도: n개의 dp 테이블을 채워야하기 때문에 O(n)이다.
해설: 나선모양으로 2개의 변을 계속 더하기 때문에 어디 값 2개가 더해지는지 규칙을 파악하면 된다.
따라서 dp[i] = dp[i-5]+dp[i-1]인 것을 알 수 있고, 반복문을 위해 dp[4]까지는 구해놔야 dp[5]부터 시작할 수 있다.
"""