어려운것 없이 쉬운 완전탐색 문제이다.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int>> d;
bool visited[8] = { false };
int out = 0;
void DFS(int cur, int cnt)
{
for(int i = 0; i < d.size(); i++)
if (!visited[i] && cur >= d[i][0])
{
visited[i] = true;
DFS(cur - d[i][1], cnt + 1);
visited[i] = false;
}
out = max(out, cnt);
}
int solution(int k, vector<vector<int>> dungeons) {
int answer = 0;
d = dungeons;
DFS(k, 0);
answer = out;
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV2 삼각 달팽이 (0) | 2022.06.01 |
|---|---|
| [프로그래머스] (C++) LV2 2개 이하로 다른 비트 (0) | 2022.06.01 |
| [프로그래머스] (C++) LV2 2 x n 타일링 (0) | 2022.05.31 |
| [프로그래머스] (C++) LV2 큰 수 만들기 (0) | 2022.05.30 |
| [프로그래머스] (C++) LV2 카펫 (0) | 2022.05.28 |