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
|
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
// 1. 입장 피로도 높은거 먼저 도는데
// 2. 소모 피로도의 크기가 작은거 먼저
int solution(int k, vector<vector<int>> dungeons)
{
int answer = 0;
vector<int> vecInt(dungeons.size(), 0);
for (int i = 0; i < vecInt.size(); ++i)
{
vecInt[i] = i;
}
do
{
int iNumber = k;
int iAnswer = 0;
for (int i = 0; i < dungeons.size(); ++i)
{
if (iNumber >= dungeons[vecInt[i]][0])
{
iNumber -= dungeons[vecInt[i]][1];
++iAnswer;
}
}
answer = max(answer, iAnswer);
} while (next_permutation(vecInt.begin(),vecInt.end()));
return answer;
}
|
cs |
처음에는 생각한 대로 while 써서 햇는데
던전 수가 8개 밖에 안되더라 그래서 완전 탐색도 괜찮겠다 싶어서 완전 탐색!
'오늘의 알고리즘' 카테고리의 다른 글
[C++]2018 KAKAO BLIND RECRUITMENT[1차] 프렌즈4블록(프로그래머스 2레벨) (0) | 2022.04.07 |
---|---|
[C++]Inheritance Accessing Inherited Functions(해커랭크 Medium) (0) | 2022.04.06 |
[C++]Classes Virtual Functions(해커랭크 Medium) (0) | 2022.04.06 |
[C++]깊이/너비 우선 탐색(DFS/BFS)단어 변환(프로그래머스 3 (0) | 2022.04.05 |
[C++]동적계획법(Dynamic Programming) 등굣길(프로그래머스 3레벨) (0) | 2022.04.04 |