Algorithm & Data Structures/Programers
Lv 2. 피로도
Geisha
2024. 6. 17. 15:02
완전탐색 문제였다.
DFS 를 이용하였고 오랜만에 사용하여 어색한 부분이 많았다.
import java.util.*;
class Solution {
public int answer=0;
public boolean[] isVisited;
public int solution(int k, int[][] dungeons) {
isVisited = new boolean[dungeons.length];
DFS(0,k,dungeons);
return answer;
}
public void DFS(int depth,int k,int[][] dungeons){
for(int i = 0 ; i < dungeons.length ; i++){
if(!isVisited[i] && k-dungeons[i][0]>=0){
isVisited[i]=true;
DFS(depth+1,k-dungeons[i][1],dungeons);
isVisited[i]=false;
}
}
answer = Math.max(answer,depth);
}
}
Math
-max(a,b)