99ํด๋ฝ ์ฝํ
์คํฐ๋ 22์ผ์ฐจ TIL : ์์ ํ์(ํ๋ก๊ทธ๋๋จธ์ค - ํผ๋ก๋)
2024. 11. 19. 11:10ใAlgorithm/ํญํด99(4๊ธฐ)

๐ ๋ฌธ์


https://school.programmers.co.kr/learn/courses/30/lessons/87946
ํ๋ก๊ทธ๋๋จธ์ค
SW๊ฐ๋ฐ์๋ฅผ ์ํ ํ๊ฐ, ๊ต์ก, ์ฑ์ฉ๊น์ง Total Solution์ ์ ๊ณตํ๋ ๊ฐ๋ฐ์ ์ฑ์ฅ์ ์ํ ๋ฒ ์ด์ค์บ ํ
programmers.co.kr
๐ก ํ์ด
- DFS
class Solution {
public int solution(int k, int[][] dungeons) {
int[] visited = new int[dungeons.length];
explore(dungeons, visited, k, 0);
return max;
}
private int max = 0;
private void explore(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;
explore(dungeons, visited, k - dungeons[i][1], count + 1);
visited[i] = 0;
}
}
if(max < count){
max = count;
}
}
}


๐ ์ค๋์ ํ๊ณ
์ด๊ธฐํํ๋ ๊ฒ์ ์์ด์ ์ด์ง ํค๋งธ๋ค..!
์ฑgpt์๊ฒ ์ค๋ช ์ ์ฝ๊ฒ ์์ฒญํด์ ์ดํดํ๋ค (ใ ใ )