From 87e7ad2fcb815f06ba20f3ad2bc69645ac5de242 Mon Sep 17 00:00:00 2001 From: sm4640 Date: Fri, 27 Mar 2026 10:30:14 +0900 Subject: [PATCH] =?UTF-8?q?9461-s3=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workbook_7319/silver/9461-s3.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 workbook_7319/silver/9461-s3.py diff --git a/workbook_7319/silver/9461-s3.py b/workbook_7319/silver/9461-s3.py new file mode 100644 index 0000000..c805947 --- /dev/null +++ b/workbook_7319/silver/9461-s3.py @@ -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]부터 시작할 수 있다. +""" \ No newline at end of file