feat: 3주차 - BOJ_2240 자두나무 [김정호] #13
Open
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.
📌 문제 링크
백준 2240번 - 자두나무


📝 문제 개요
🧩 풀이 요약
이동 횟수(W)이 행, 시간(T)이 열인 2차원 배열 dp를 사용한다.
이동을 안한 경우 (w == 0)
현재 위치와 열매가 떨어지는 위치가 같다면 이전 시간의 같은 이동 횟수의 값 +1
위치가 다르면 이전 시간의 같은 이동 횟수의 값 그대로
이동을 하는 경우 (w >= 1)
현재 위치에 열매가 떨어지는 경우,
가만히 있는 경우: dp[w][t-1] + 1
움직인 경우: dp[w-1][t-1] + 1
위의 두 경우 중 더 큰 값을 dp[w][t]에 저장한다.
현재 위치와 열매가 떨어지지 않은 경우
가만히 있는 경우: dp[w-1][t]
움직인 경우: dp[w-1][t-1]
위의 두 경우 중 더 큰 값을 dp[w][t]에 저장한다.
😁 결과