Skip to content

Conversation

@jiwonsudo
Copy link
Contributor

🔎 문제 소개

🖊️ 풀이

  • 시간 복잡도:
  • 입력의 크기:
    • (예시) 2 <= $N <= 20

DFS라는 알고리즘의 한 형태를 처음 사용해 보았습니다. 재귀함수를 사용하는 것은 괜찮으나 재귀함수를 사용하는 알고리즘을 어떻게 최적화해야 할 지가 DFS 문제에서 가장 어려웠던 것 같습니다 ㅠㅠ

Comment on lines +2 to +13
Copy link
Member

Choose a reason for hiding this comment

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

solution()numbers, targetdfs()안에서도 충분이 참조가 가능하니, 인자를 줄여보아도 괜찮을 것 같아요!

풀이는 전반적으로 아주 나이스하군요! 고생하셨습니다.

def solution(numbers, target):    
    def count_cases_by_dfs(index = 0, current = 0):
        if index == len(numbers):
            return 1 if current == target else 0
        return count_cases_by_dfs(index+1, current+numbers[index]) + count_cases_by_dfs(index+1, current-numbers[index])
    return count_cases_by_dfs()

Copy link
Member

Choose a reason for hiding this comment

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

hmm.. 지난 주차에 올렸던 파일인데 왜 같이 올라왔을까요... 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

저 지난주 PR이 인 받아져서 엎쳐서 들어간 거 같아요.. ㅠㅠㅠ 해결법을 몰라서 덮어썼습니자

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.

2 participants