문제링크: 피로도
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️⭐️+0.5 |
| 풀이시간 | 15분 |
| 제출횟수 | 2 |
| 인터넷검색유무 | yes |
🍒 My Code
import itertools
def solution(k, dungeons):
answer = 0
seq = list(itertools.permutations([i for i in range(len(dungeons))],len(dungeons)))
for i in seq:
tmpk,tmpresult = k, 0
for j in i:
if dungeons[j][0]>tmpk: #최소 피로도만큼 없음
continue
tmpk-=dungeons[j][1]
tmpresult+=1
answer=max(answer,tmpresult)
return answer
💡 What I learned
2차원 list에서 각 list의 첫번째값을 기준으로 정렬: list_name.sort(key=lambda x:x[0])순열: itertools의 permutation-> dfs 사용해서 다시 풀어보기