![[고득점kit/완전탐색] 피로도 [고득점kit/완전탐색] 피로도](https://blog.kakaocdn.net/dn/bL0rti/btsnGkhF6xR/X5nU7AiFKF0X1gLywGQj21/img.png)
class Solution {
static boolean[] visited;
static int max = 0;
void explore(int piro, int[][] dungeons, int cnt) {
// 모든 케이스 순회
for (int i = 0; i < dungeons.length; i++) {
int a = dungeons[i][0];
int b = dungeons[i][1];
// 기존에 방문 확인, 최소 피로도 확인
if (visited[i] || piro < a) {
continue;
}
// 방문
visited[i] = true;
explore(piro - b, dungeons, cnt + 1);
// 다른 케이스를 위해 방문 취소
visited[i] = false;
}
max = Math.max(max, cnt);
}
public int solution(int k, int[][] dungeons) {
visited = new boolean[dungeons.length];
explore(k, dungeons, 0);
return max;
}
}
진짜...재귀가 너무 싫구요 fatigue/exhaustion 이런게 바로 생각이 안나서 그냥 piro..
'Algorithm > 프로그래머스' 카테고리의 다른 글
[Lv. 1] 햄버거 만들기 (0) | 2023.07.29 |
---|---|
[Level 1] 숫자 문자열과 영단어 (0) | 2023.07.23 |
[고득점kit/완전탐색] 모의고사 (0) | 2023.07.06 |
[고득점kit/깊이/너비 우선 탐색] 타겟 넘버 (0) | 2023.06.22 |
[고득점kit/완전탐색] 모음 사전 (0) | 2023.06.22 |
댓글