๋ฌธ์ ๐ฝ
https://school.programmers.co.kr/learn/courses/30/lessons/87946
๋ค๋ฅธ์ฌ๋ ํ์ด ๐ฝ
function solution(k, d) {
const N = d.length
const visited = new Array(N).fill(0)
let ans = 0
function dfs(k, cnt){
ans = Math.max(cnt, ans)
for (let j = 0; j < N; j++){
if (k >= d[j][0] && !visited[j]){
visited[j] = 1
dfs(k - d[j][1], cnt + 1)
visited[j] = 0
}
}
}
dfs(k, 0)
return ans;
}
๋ดํ์ด๐ฝ
1. ์ฑ๊ณต โญ
function solution(k, dungeons) {
let result = []
const visited = Array.from(dungeons,()=>false)
const dfs=(hp,round)=>{
result.push(round)
for(let i=0; i<visited.length; i++){
if(!visited[i]&&hp>=dungeons[i][0]){
visited[i]=true;
dfs(hp-dungeons[i][1],round+1)
visited[i]=false;
}
}
}
dfs(k,0)
return Math.max(...result)
}
๋๋์ ๐ฝ
๋ณต์กํ ์ฌ๊ทํจ์์ ๋ํ ๊ฒฝํ์ ์์ ์ ์์ด ์ข์๋ค.