소스 코드
from itertools import permutations
def solution(k, dungeons):
path_list = list(permutations(dungeons, len(dungeons)))
answer_list = []
for path in path_list:
cur_fatigue = k
count = 0
for dungeon in path:
if cur_fatigue < dungeon[0]:
break
cur_fatigue -= dungeon[1]
count += 1
answer_list.append(count)
return max(answer_list)
풀이
문제의 제한사항에서 던전의 개수는 1이상 8이하라고 하였으므로 이 또한 모든 던전의 형태를 구한 다음 각 던전을 순회하면서 solution을 구하는 방식을 택하였다.
먼저 permutations를 사용하여 모든 던전을 탐험하는 path를 구한 다음 해당 path를 순회하며 조건에 맞을 경우 count를 1씩 증가하였다.
'Python > 알고리즘' 카테고리의 다른 글
완전탐색 Level 2 전력망을 둘로 나누기 - python (프로그래머스) (0) | 2023.06.23 |
---|---|
완전탐색 Level 2 모음사전 - python (프로그래머스) (0) | 2023.06.23 |
완전탐색 Level 2 카펫 - python (프로그래머스) (0) | 2023.06.23 |
완전탐색 Level 2 소수 찾기 - python (프로그래머스) (0) | 2023.06.23 |
완전탐색 Level 1 최소직사각형 - python (프로그래머스) (0) | 2023.06.23 |