Skip to content

Commit

Permalink
[프로그래머스] 피로도
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdgua01 committed Sep 9, 2024
1 parent 9c68237 commit 446e29f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions coding_test/programmers/brute_force/fatigue_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def solution(k, dungeons):
result = []
dfs(k, dungeons, 0, result)
return max(result, default=0)


def dfs(k, dungeons, n, result):
available_dungeons = [[m, c] for m, c in dungeons if m <= k]
if not available_dungeons:
result.append(n)
return
for i, (m, c) in enumerate(available_dungeons):
dfs(
k=k - c,
dungeons=(d for j, d in enumerate(available_dungeons) if j != i),
n=n + 1,
result=result,
)


def test_cases():
assert solution(80, [[80, 20], [50, 40], [30, 10]]) == 3

0 comments on commit 446e29f

Please sign in to comment.