answer = 0
def solution(k, dungeons):
def DFS(cnt, dungeons, k, visited):
global answer
answer = max(answer, cnt)
for i in range(len(dungeons)):
if visited[i] == 0 and k >= dungeons[i][0]:
visited[i] = 1
DFS(cnt+1, dungeons, k-dungeons[i][1], visited)
visited[i] = 0
visited = [0] * len(dungeons)
DFS(0, dungeons, k, visited)
return answer
DFS와 백트래킹 알고리즘을 활용하여 다음 문제를 해결할 수 있다.