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개 밖에 안되더라 그래서 완전 탐색도 괜찮겠다 싶어서 완전 탐색!

+ Recent posts