https://school.programmers.co.kr/learn/courses/30/lessons/87946
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(int k, vector<vector<int>> dungeons) {
//24.10.22
int answer = 0;
sort(dungeons.begin(), dungeons.end());
do {
int nk = k;
int ch = 0;
for (auto it = dungeons.begin(); it != dungeons.end(); ++it)
{
if (nk >= (*it)[0])
{
nk -= (*it)[1];
++ch;
}
}
answer = max(answer, ch);
} while (next_permutation(dungeons.begin(), dungeons.end()));
return answer;
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (동적계획법(Dynamic Programming)) Lv 3. N으로 표현 (0) | 2024.10.26 |
---|---|
[Programmers] (깊이/너비 우선 탐색(DFS/BFS)) Lv 3. 네트워크 (2) | 2024.10.23 |
[Programmers] (동적계획법(Dynamic Programming)) Lv 3. 정수 삼각형 (0) | 2024.10.21 |
[Programmers] (완전탐색) Lv 2. 소수 찾기 (0) | 2024.10.21 |
[Programmers] (정렬) Lv 2. H-Index (0) | 2024.10.17 |
댓글