This repository was archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
[2023-09-20] dohyun #238 #256
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,28 @@ | ||
| """ | ||
|
|
||
| 풀이시간 | ||
| - 약 1시간 풀이 후 실패로 답지 참조 | ||
|
|
||
| 접근법 | ||
| - N 10만 이하 -> O(NlogN) | ||
| - 그리디? -> 현재 행에서 최대라고 해서 합이 최대가 되는게 아니기 때문에 X | ||
| - 열은 왜 4개로 고정? -> 각 열별로 결과를 저장해놓으면 될듯 | ||
| - 현재 열을 제외한 이전 행의 최대값과 현재 열의 값을 계속해서 더해가며 갱신하면 될듯 | ||
|
|
||
| 회고 | ||
| - 로직은 같은데 1차원 배열로만 해결하려다가 사고가 멈춰버린듯함 ㅠㅠ | ||
| - DP테이블은 2차원 배열도 가능하다는거 꼭 인지하기 | ||
|
|
||
| """ | ||
|
|
||
| def solution(land): | ||
| N = len(land) | ||
|
|
||
| dp = [[0] * 4 for _ in range(N)] # DP 테이블 | ||
| dp[0] = land[0] | ||
|
|
||
| for i in range(1, N): | ||
| for j in range(4): | ||
| dp[i][j] = land[i][j] + max(dp[i-1][:j] + dp[i-1][j+1:]) # 이전 행에서 같은 열을 제외한 나머지 열 중에서 최대 점수 더함 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 저도 이렇게 접근을 하다가 land[i][j]를 업데이트 하는 것이 더 좋겠다는 생각을 했었습니다! 고생하셨어요 도현님! |
||
|
|
||
| return max(dp[-1]) # 최대 점수 반환 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
dp 배열을 굳이 만들 필요없이 어차피 아래로 내려가는 구조니까 land배열을 그대로 사용하면 메모리 사용량을 줄일 수 있어요!!