문제는 쉽다.
근데 처음 보는 입력 형식에서 당황했다.
그리고 n=0일때
0가지 아닌가,,,?
1가지로 풀어야 한단다,,
그리고
try except 안써주면 런타임 에러 뜬다.
# dp 설계
dp = [
0 for _ in range(251)
]
# dp 초기설정
dp[0] = 1
dp[1] = 1
dp[2] = 3
# dp 채워넣기
for i in range(3, 251):
dp[i] = dp[i-2] * 2 + dp[i-1]
while True:
try:
# n 입력
n = int(input())
# 출력
print(dp[n])
except:
break
'Algorithm(BOJ, Python) > Dynamic Programing' 카테고리의 다른 글
[백준_4883] 삼각 그래프 python (0) | 2022.07.30 |
---|---|
[백준_9711] 피보나치 python (0) | 2022.07.29 |
[백준_8394] 악수 python (0) | 2022.07.27 |
[백준_17175] 피보나치는 지겨웡~ python (0) | 2022.07.26 |
[백준_9507] Generation of Tribbles python (0) | 2022.07.25 |