[프로그래머스] 필요도

박신희·2022년 4월 12일
0

[풀이] 프로그래머스

목록 보기
14/33
post-thumbnail

❗️풀이 과정

  • permutations를 사용한 게 핵심이었던 것 같다.
  • stat변수를 통해 가능한 던전 개수를 더해준 다음
    able리스트에 저장해두고
    가능한 던전 개수 중에 최댓값을 반환한다.

🤜 풀이 코드


from itertools import permutations
def solution(k, dungeons):
    answer = 0
    able=[]
    for d in permutations(dungeons,len(dungeons)):
        stat=0
        piro=k
        for p,m in d:
            if piro>=p:
                piro-=m
                stat+=1
            else:
                break
        able.append(stat)
        
    return max(able)
profile
log my moments 'u')/

0개의 댓글