!https://workat.tech/images/ps/dfs-of-acyclic-graph.svg
프로그래머스 예제 : 87946
https://school.programmers.co.kr/learn/courses/30/lessons/87946
private static void dfs(int[][] dungeons, int[] visited, int k, int count){
for(int i = 0; i < dungeons.length; i++){
if(visited[i] == 0 && k >= dungeons[i][0]){
visited[i] = 1;
dfs(dungeons, visited, k - dungeons[i][1], count + 1);
visited[i] = 0;
}
}
if(amswer < count){
amswer = count;
}
}
프로그래머스 예제 : 43165
https://school.programmers.co.kr/learn/courses/30/lessons/43165
public static void dfs(int[] numbers, int depth, int target, int result) {
if (depth == numbers.length) {
if (target == result) {
count++;
}
return;
}
int plus = result + numbers[depth];
int minus = result - numbers[depth];
dfs(numbers, depth+1, target, plus);
dfs(numbers, depth+1, target, minus);
}