던전의 길이가 최대 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