1003-s3 성공

This commit is contained in:
sm4640
2026-03-26 23:02:47 +09:00
parent f28354b79c
commit 81fd3ef46e

View File

@@ -0,0 +1,33 @@
# 피보나치 함수
import sys
input = sys.stdin.readline
def solution():
t = int(input().rstrip())
dp = [0] * 50
dp[0] = (1, 0)
dp[1] = (0, 1)
for i in range(2, 50):
dp[i] = (dp[i-1][0]+dp[i-2][0], dp[i-1][1]+dp[i-2][1])
for _ in range(t):
k = int(input().rstrip())
print(*dp[k])
return
solution()
"""
걸린 시간: 15분
시간 복잡도: n은 40보다 작다고 했기 때문에 dp테이블을 대략 50까지만 채우면 되므로 O(n)이다.
해설: 현재 보는 수는 결국 1개 전과, 2개 전에 사용했던 0, 1의 개수의 합이므로 dp 테이블을 만들어서 계속 채워나가면 된다.
"""