«   2025/09   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Recent Posts
Tags more
Today
Total
관리 메뉴

내 인생은 개발 중

[프로그래머스] 피로도 - Python 본문

Algorithm/프로그래머스

[프로그래머스] 피로도 - Python

seul.e 2024. 5. 16. 23:27

https://school.programmers.co.kr/learn/courses/30/lessons/87946

 

프로그래머스

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

programmers.co.kr

 

풀이

from itertools import permutations

def solution(k, dungeons):
    answer = 0
    hp = k
    for permute in permutations(dungeons, len(dungeons)):
        temp_count = 0
        hp = k
        for pm in permute:
            if hp >= pm[0]:
                hp -= pm[1]
                temp_count += 1
        answer = max(answer, temp_count)

    return answer

 

💡알게 된 점💡

permutation(객체, 몇 개로 조합할 것인지) 으로 사용한다.

permutation은 combination과 달리 순서를 고려하여, 중복 없이 뽑을 경우의 수를 뽑아낸다.

Comments