Skip to content

Conversation

@SollyJ
Copy link
Contributor

@SollyJ SollyJ commented Mar 28, 2023

📖 풀이한 문제

  • 도둑질

💡 문제에서 사용된 알고리즘

  • 다이나믹 프로그래밍

📜 코드 설명

  • 집이 원형으로 배치 되어 있기 때문에 다음 두 경우로 나눠보자.
    a. 첫번째 집을 터는 경우
    b. 첫번째 집을 털지 않는 경우

  • 다이나믹 프로그래밍의 풀이순서는 다음과 같다.

  1. 테이블 정의
    n번째 집을 털었을 때 총 훔친 돈의 최댓값 이 들어갈 배열 정의

  2. 초기값 세팅
    각 집에 있는 돈을 넣어준다.

    a. 첫번째 집을 터는 경우
    dp_first[1] = -1;
    dp_first[2] += dp_first[0];

    b. 첫번째 집을 털지 않는 경우
    dp_second[0] = -1;

  3. 점화식 선언
    인접하지 않은 두 집(i - 2, i - 3번째 집)을 비교해 더 큰 값을 누적해 더한다.

  4. 답구하기
    맨 마지막 두집을 비교해 dp_first 배열과 dp_second 배열에서 최댓값을 구하고,
    그 둘 중에서 최댓값이 answer!

close #62


@SollyJ SollyJ added this to the 4주차 milestone Mar 28, 2023
@SollyJ SollyJ requested a review from a team as a code owner March 28, 2023 14:03
@SollyJ SollyJ self-assigned this Mar 28, 2023
@SollyJ SollyJ enabled auto-merge May 16, 2023 12:35
@SollyJ SollyJ disabled auto-merge May 16, 2023 12:36
@SollyJ SollyJ requested review from j2woo and soojik and removed request for a team May 16, 2023 12:38
@SollyJ SollyJ closed this by deleting the head repository May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[정솔리] 도둑질

1 participant