나의 개발일지

[프로그래머스] Lv.2 피로도 [Python, 파이썬] 본문

프로그래머스

[프로그래머스] Lv.2 피로도 [Python, 파이썬]

YoonJuHan 2023. 9. 16. 17:31
from itertools import permutations

def solution(k, dungeons):

    all = [i for i in permutations(dungeons,len(dungeons))] # 순열 구하기

    ok = [] # 조합별로 탐험 횟수 담을 리스트

    for i in range(len(all)):
        fatigue = k     # 피로도
        count = 0       # 탐험 횟수
        for j in all[i]:
            if fatigue >= j[0]:     # 최소 피로도 만족하면
                fatigue -= j[1]     # 소모 피로도만큼 차감
                count += 1          # 탐험 횟수 증가
            elif fatigue < j[0]:    # 최소 피로도 부족하면
                break               # 반복 종료

        ok.append(count)    # 하나의 조합마다 탐험 횟수를 저장    

    return max(ok)  # 가장 많은 탐험 횟수 리턴

print(solution(80, [[80,20],[50,40],[30,10]]))
Comments