[프로그래머스] 피로도

joon_1592·2022년 5월 20일

알고리즘

목록 보기
45/51

던전의 길이가 최대 8이므로 모든 경우의 수는 8!이다.
8!은 1초안에 계산이 가능한 계산량이다

from itertools import permutations

def solution(k, dungeons):
    answer = -1
    N = len(dungeons)
    perms = permutations(dungeons, N)
    for perm in perms:
        rest_k = k
        count = 0
        for req, cost in perm:
            if rest_k >= req:
                rest_k = rest_k - cost
                count += 1
        answer = max(answer, count)
    return answer
profile
공부용 벨로그

0개의 댓글