❓  문제

피로도

 

🛎️  아이디어

1. permutations를 사용해서 던전의 수만큼의 range 순열을 만든다.

2. 각각의 순열에서 통과한 던전의 수를 보관할 answer 배열을 만든다.

3. permutations로 생성한 순열들을 돌면서 피로도 계산을 한다.

4. answer 배열에서의 가장 큰 값을 return 한다.

 

💻  풀이

from itertools import permutations

def solution(k, dungeons):
  permutaion = list(permutations(range(len(dungeons)), len(dungeons)))
  answer = []

  for pmt in permutaion:
    # 통과한 던전 수
    pass_num = 0

    # 초기 피로도
    fatigue = k

    for p in pmt:
      if fatigue >= dungeons[p][0]:
        fatigue -= dungeons[p][1]
        pass_num += 1

    answer.append(pass_num)

  return max(answer)

 

+ Recent posts