728x90
https://www.acmicpc.net/problem/19947
접근 방법
1. n년 후의 최적의 값을 도출하여야 한다.
2. 받을 수 있는 이자의 방식이 3가지이므로 1년, 3년, 5년 전의 값에서 투자 방식에 따라 최대 값으로 갱신해주면 된다.
import sys
sys.stdin = open('input.txt')
input = sys.stdin.readline
H, Y = map(int, input().split())
results = [0] * (Y+1)
results[0] = H
for i in range(1, Y+1):
for j in [1, 3, 5]:
if i - j < 0:
break
if j == 1:
val = int(results[i-j] * 1.05)
elif j == 3:
val = int(results[i-j] * 1.2)
else:
val = int(results[i-j] * 1.35)
results[i] = max(results[i], val)
print(results[-1])
728x90
'ALGORITHM > DP(동적 계획법)' 카테고리의 다른 글
[백준 14925번] 파이썬 - 목장 건설하기 (0) | 2024.10.31 |
---|---|
[백준 18427번] 파이썬 - 함께 블록 쌓기 (1) | 2024.10.30 |
[백준 1535번] 파이썬 - 안녕 (0) | 2024.10.30 |
[백준 13699번] 파이썬 - 점화식 (0) | 2024.05.29 |
[백준 11048번] 파이썬 - 이동하기 (0) | 2024.05.06 |