https://school.programmers.co.kr/learn/courses/30/lessons/87946
#include <string>
#include <vector>
using namespace std;
int dfs(int& k, vector<vector<int>>& dungeons, int idx, int answer, vector<bool>& visit)
{
k -= dungeons[idx].back(), visit[idx] = true;
int res = answer;
if (answer == dungeons.size())
return res;
for (int i = 0; i < dungeons.size(); ++i)
{
if (visit[i] || k < dungeons[i].front()) continue;
res = max(dfs(k, dungeons, i, answer + 1, visit), res);
k += dungeons[i].back(), visit[i] = false;
}
return res;
}
int solution(int k, vector<vector<int>> dungeons) {
int answer = 0, origin = k;
vector<bool> visit(dungeons.size(), false);
for (int i = 0; i < dungeons.size(); ++i)
{
answer = max(dfs(k, dungeons, i, 1, visit), answer);
k = origin, visit[i] = false;
}
return answer;
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (해시) Lv 2. 전화번호 목록 (0) | 2023.06.26 |
---|---|
[Programmers] (깊이/너비 우선 탐색(DFS/BFS)) Lv 2. 타겟 넘버 (0) | 2023.06.22 |
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [1차] 뉴스 클러스터링 (0) | 2023.06.16 |
[Programmers] (스택/큐) Lv 2. 프로세스 (0) | 2023.06.16 |
[Programmers] Lv 2. 할인 행사 (0) | 2023.06.16 |
댓글