최대 1 분 소요

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


실행결과_js ver 1.0


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])


실행결과_js ver 1.1


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


실행결과_js ver 1.1


업데이트: