Skip to content

Conversation

@JSY8869
Copy link
Collaborator

@JSY8869 JSY8869 commented Nov 4, 2021

16-3 퇴사

바텀업 방식인데 위에서 아래로 내려오는 방식으로 해결하였습니다. DP 알고리즘이 익숙하지 않아서 복습하면서 풀어보니 생각보다 어려운 문제는 아니었네요ㅎㅎ
(자동으로 테스트가 진행되도록 코드를 작성했습니다)

16-4 병사 배치하기

뭔가 DP 알고리즘은 아니고 구현 파트처럼 해결하였습니다. 그냥 머릿속에서 생각한 방식을 그대로 코드로 바꿔보니 해결이 되었습니다....ㅎㅎ

@JSY8869 JSY8869 added the Pull Request Pull Request label Nov 4, 2021
@JSY8869 JSY8869 added this to the Coding Test milestone Nov 4, 2021
@JSY8869 JSY8869 requested review from fora22 and jongfeel November 4, 2021 13:52
@JSY8869 JSY8869 self-assigned this Nov 4, 2021
@JSY8869 JSY8869 changed the title 16-3 퇴사 완료, 16-4 병사 배치하기 미완료 16-3 퇴사 완료, 16-4 병사 배치하기 완료 Nov 8, 2021
@jongfeel
Copy link
Collaborator

jongfeel commented Nov 9, 2021

퇴사 문제 한번 백준에 돌려 보고 결과 알려주세요

불필요한 조건 제거
@JSY8869
Copy link
Collaborator Author

JSY8869 commented Nov 9, 2021

아래 코드처럼 입력, 출력 형식만 바꿔서 넣어보니 정답 나오네요ㅎㅎ
병사 배치하기 문제 if문도 수정하였습니다
image

N = int(input())
TiPi = []
Ti = []
Pi = []

for _ in range(N):
    TiPi.append(input().split())


for i in range(len(TiPi)):
    Ti.append(int(TiPi[i][0]))
    Pi.append(int(TiPi[i][1]))

d = [0 for _ in range(N+1)]

for i in range(N-1, -1, -1):
    if i + Ti[i] > N:
        d[i] = d[i+1]
    else:
        d[i] = max(d[i+1], Pi[i] + d[i + Ti[i]])

print(d[0])

Copy link
Collaborator

@jongfeel jongfeel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@JSY8869 JSY8869 merged commit c388629 into JSY8869/Develop Nov 12, 2021
@JSY8869 JSY8869 deleted the JSY8869/Feature/CodingTest/Chater16 branch November 12, 2021 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Pull Request Pull Request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants