Skip to content

Commit 1681466

Browse files
authored
Create 5.py
1 parent 58ed118 commit 1681466

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎8/5.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 정수 N을 입력 받기
2+
n = int(input())
3+
# 모든 식량 정보 입력 받기
4+
array = list(map(int, input().split()))
5+
6+
# 한 번 계산된 결과를 메모이제이션(Memoization)하기 위한 리스트 초기화
7+
d = [0] * 100
8+
9+
# 다이나믹 프로그래밍(Dynamic Programming) 진행 (Bottom-top)
10+
d[0] = array[0]
11+
d[1] = max(array[0], array[1])
12+
for i in range(2, n):
13+
d[i] = max(d[i - 1], d[i - 2] + array[i])
14+
15+
# 계산된 결과 출력
16+
print(d[n - 1])

0 commit comments

Comments
 (0)