-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#17 : Week4_예원이티
- Loading branch information
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
n = int(input()) | ||
score = [] | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
dp = [] | ||
|
||
for _ in range(n): | ||
score.append(int(input())) | ||
|
||
dp[0] = score[0] | ||
dp[1] = score[0] + score[1] | ||
dp[2] = max(score[0] + score[2], score[1] + score[2]) | ||
for i in range(3, n): | ||
dp[i] = max(score[i] + dp[i-2], score[i] + score[i-1] + dp[i-3]) | ||
|
||
print(dp[n-1]) |
1 comment
on commit de89484
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
score과 dp를 모두 0으로 채워진 리스트로 처음부터 선언해주어야 런타임 에러가 발생하지 않습니다! 그리고 for문 안에 score 리스트를 입력 받을 때에도 append 대신 인덱스를 사용하여 넣어주어야 런타임 에러가 발생하지 않습니다! 이 부분 고쳐서 다시 커밋해주세요! 문제 푸시느라 고생하셨습니다 :)