728x90
- 문제
- 해결
import sys
resignation_day = sys.stdin.readline()
time_and_pay = [list(map(int, x.strip().split())) for x in sys.stdin.readlines()]
time_list = [x[0] for x in time_and_pay]
pay_list = [x[1] for x in time_and_pay]
cand = [0]
def go(time_list, pay_list, cur_ind, cumulative_pay):
# 불가능
if cur_ind >= len(time_list):
return None
# 정답
if (cur_ind + time_list[cur_ind]) > len(time_list):
if cand[0] < cumulative_pay:
cand[0] = cumulative_pay
if (cur_ind + time_list[cur_ind]) == len(time_list):
if cand[0] < (cumulative_pay + pay_list[cur_ind]):
cand[0] = cumulative_pay + pay_list[cur_ind]
go(time_list, pay_list, cur_ind + time_list[cur_ind], cumulative_pay + pay_list[cur_ind])
go(time_list, pay_list, cur_ind + 1, cumulative_pay)
return cand[0]
print(go(time_list, pay_list, 0, 0))
- 포인트
- Dynamic programming
728x90
'Algorithm-Problems > 백준' 카테고리의 다른 글
[백준][14500] 테트로미노 (0) | 2022.05.08 |
---|---|
[백준][13023] ABCDE (0) | 2022.05.08 |
[백준][11724] 연결 요소의 개수 (0) | 2022.05.08 |
[백준][10972] 다음 순열 (0) | 2022.05.08 |
[백준][10819] 차이를 최대로 (0) | 2022.05.08 |