Algorithm/Programmers

programmers_피로도_java

owoowo 2023. 4. 6. 17:52
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/87946

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    
    private static int max;
    public int solution(int k, int[][] dungeons) {
        int answer = -1;
        
        max = 0;
        dfs(k, dungeons, 0, new boolean[dungeons.length]);
        
        answer = max;
        return answer;
    }
    
    public void dfs(int k, int[][] dungeons, int cnt, boolean[] visited){
        int dungeonsLength = dungeons.length;
        
        max = Math.max(max, cnt);
        
        for(int i = 0; i<dungeonsLength; i++){
            if(!visited[i] && k >= dungeons[i][0]){  
                visited[i] = true;
                dfs(k-dungeons[i][1], dungeons, cnt + 1,visited);
                visited[i] = false;
            }
        }
    }
}