코딩테스트/프로그래머스

[프로그래머스] [Level 2] [완전탐색] 피로도

박소민 2022. 8. 12. 13:46
피로도
 

프로그래머스

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

programmers.co.kr

 

  • 내 풀이
    • 순열(permutations) 이용
    • 가능한 순서를 모두 적용해보면서 최댓값 구함
from itertools import permutations

def solution(k, dungeons):
    count=0
    answer=0
    k2=k
    n= len(dungeons)
    lst=[i for i in permutations(range(n),n)]
    for ls in lst:
        for l in ls:
            if k2>=dungeons[l][0]:
                k2-=dungeons[l][1]
                count+=1
        answer=max(answer,count)
        count=0
        k2=k
    
    return answer