최대 1 분 소요

문제 링크

프로그래머스-피로도

문제 풀이

def dfs(current,k,dungeons,visited,depth):
    max_depth = 0
    
    for i in range(len(dungeons)):
        if visited[i] == False and k >= dungeons[i][0]:
            visited[i]=True
            max_depth = max(max_depth, dfs(i,k - dungeons[i][1],dungeons,visited,depth+1))  
            visited[i]=False
    return max(depth,max_depth)

def solution(k, dungeons):
    answer = -1
    length = len(dungeons)
    
    
    for i in range(len(dungeons)):
        visited = [False for x in range(length)]
        answer = max(answer,dfs(i,k,dungeons,visited,0))
    
    return answer

댓글남기기