-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy path49.cpp
More file actions
46 lines (33 loc) · 1.08 KB
/
Copy path49.cpp
File metadata and controls
46 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int maxDepth = 0;
bool visited[8] = {false, };
//❶ 최대방문 던전수를 갱신하면서 깊이우선탐색으로 던전을 탐험
void exploreDungeon(int depth, int power, vector<vector<int>>& dungeons) {
if(maxDepth < depth)
maxDepth = depth;
for(int i = 0; i < dungeons.size(); i++) {
//❷ 이미 방문한 던전이거나, 최소 필요 피로도가 현재 남은 피로도 보다 많은 경우
if(visited[i] || dungeons[i][0] > power)
continue;
//❸ 방문이 가능한 가능한 모든 경우를 확인
visited[i] = true;
exploreDungeon(depth + 1, power - dungeons[i][1], dungeons);
visited[i] = false;
}
}
int solution(int initialPower,vector<vector<int>> dungeons) {
//❹ 던전탐색 시작
exploreDungeon(0, initialPower, dungeons);
return maxDepth;
}
//아래 코드는 테스트 코드 입니다.
#include <iostream>
using namespace std;
int main()
{
cout << solution(80, {{80, 20}, {50, 40}, {30, 10}}) << endl; // 출력값 : 3
return 0;
}