Pepperminttt
Pepperminttt's Dev
Pepperminttt
전체 방문자
오늘
어제
  • devInfo (86)
    • forBeingGoodDeveloper (2)
    • React (2)
      • LostArk Open API (1)
    • algorithm (58)
      • problems (44)
      • theory (14)
    • computerScience (8)
      • network (8)
    • javaScript (8)
    • Java (4)
    • web (2)
      • webApplication (2)
    • etc. (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • BFS
  • DP문제
  • C++
  • solved.ac
  • node.js
  • 그래프
  • dfs문제
  • 탐욕법
  • DP
  • 알고리즘
  • dfs
  • Network
  • 탐욕법 문제
  • 프로그래머스
  • Java
  • greedy
  • 벨만-포드
  • JavaScript
  • bfs문제
  • 백준

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Pepperminttt

Pepperminttt's Dev

[프로그래머스 / C++] 피로도
algorithm/problems

[프로그래머스 / C++] 피로도

2023. 5. 17. 17:20

문제

https://school.programmers.co.kr/learn/courses/30/lessons/87946

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


문제 해설

해당 문제는 일정 피로도로 최대한 많은 던전을 들어가는 방법을 찾는 문제이다. 문제의 중요한 조건을 정리하면 아래와 같다.

 

1. 던전에 들어가기 위해서는 최소 필요 피로도 이상의 피로도가 있어야 한다.

2. 던전에 들어가면 소모 피로도만큼 현재 피로도에서 감소한다.

3. 한 번 들어간 던전은 다시 들어갈 수 없다.

4. 던전의 수는 최소 1개, 최대 8개이다.

 

위 조건을 확인하면 DFS를 통한 완전 탐색을 통해 최대 입장 횟수를 구할 수 있다.

 

#include <string>
#include <vector>
#include <iostream>

using namespace std;

vector<bool> visited;
vector<int> minEnergy;
vector<int> useEnergy;

int maxEnter = 0;
int dungeonSize = 0;

void enterTheDungeon (int count, int energy){
    for(int i = 0; i < dungeonSize; i++){
        if(!visited[i] && energy >= minEnergy[i]){
            visited[i] = true;
            enterTheDungeon(count+1,energy-useEnergy[i]);
            visited[i] = false;
        }
    }
    if(maxEnter < count){
        maxEnter = count;
    }
}


int solution(int k, vector<vector<int>> dungeons) {
    int answer = -1;
    dungeonSize = dungeons.size();
    
    for(vector<int> x : dungeons){
        visited.push_back(false);
        minEnergy.push_back(x[0]);
        useEnergy.push_back(x[1]);
    }
    
    enterTheDungeon(0,k);
    return maxEnter;
}

 

'algorithm > problems' 카테고리의 다른 글

[프로그래머스 / C++] 롤케이크 자르기  (0) 2023.05.18
[프로그래머스 / C++] 모음 사전  (0) 2023.05.18
[LeetCode] 258. Add Digits  (0) 2023.04.26
[백준]1107번 리모컨  (0) 2022.11.26
[백준] 1072번 Z _ Node_js  (0) 2022.11.21
    'algorithm/problems' 카테고리의 다른 글
    • [프로그래머스 / C++] 롤케이크 자르기
    • [프로그래머스 / C++] 모음 사전
    • [LeetCode] 258. Add Digits
    • [백준]1107번 리모컨
    Pepperminttt
    Pepperminttt
    HTML, JavaScript, Python 등 Computer language TIL

    티스토리툴바