프로그래머스 - 피로도
part40. 피로도
py ver 1.0
def solution(k, dungeons):
if not dungeons or k <= 0:
return 0
max_clearance = 0
for i, (condition, fatigue) in enumerate(dungeons):
if k >= condition:
clearance = solution(k - fatigue, dungeons[:i] + dungeons[i+1:]) + 1
max_clearance = max(max_clearance, clearance)
return max_clearance
py ver 1.1
solution = lambda k, dungeons: max([solution(k - fatigue, dungeons[:i] + dungeons[i+1:]) + 1 for i, (condition, fatigue) in enumerate(dungeons) if k >= condition] or [0])
py ver 1.2
from itertools import permutations
def solution(k, dungeons):
max_clearance = 0
for select in permutations(dungeons, len(dungeons)):
orgK = k
cnt = 0
for condition, fatigue in select:
if orgK >= condition:
orgK -= fatigue
cnt += 1
max_clearance = max(max_clearance, cnt)
return max_clearance