Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6-ljedd2 #141

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion LJEDD2/2024-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
| 2μ°¨μ‹œ | 2024.07.20 | λ‹€μ΄λ‚˜λ―Ήν”„λ‘œκ·Έλž˜λ° | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/42895">N으둜 ν‘œν˜„</a> | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/126) |
| 3μ°¨μ‹œ | 2024.07.24 | 깊이/λ„ˆλΉ„ μš°μ„  탐색(DFS/BFS) | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/43164">μ—¬ν–‰κ²½λ‘œ</a> | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/131) |
| 4μ°¨μ‹œ | 2024.07.27 | κ·Έλž˜ν”„ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/49189">κ°€μž₯ λ¨Ό λ…Έλ“œ</a> | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/133) |
---
| 5μ°¨μ‹œ | 2024.07.31 | λ‹€μ΄λ‚˜λ―Ήν”„λ‘œκ·Έλž˜λ° | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/43105">μ •μˆ˜ μ‚Όκ°ν˜•</a> | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/139) |
| 6μ°¨μ‹œ | 2024.08.03 | 완전탐색 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/87946">ν”Όλ‘œλ„</a> | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/141) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def solution(triangle):
for row in range(1, len(triangle)):
for col in range(row + 1):
if col == 0:
triangle[row][col] += triangle[row-1][col] # λ°”λ‘œ μœ„ ν–‰ 같은 μ—΄
elif col == row:
triangle[row][col] += triangle[row-1][col-1] # λ°”λ‘œ μœ„ ν–‰μ˜ μ™Όμͺ½ μ—΄
else:
right, left = triangle[row-1][col], triangle[row-1][col-1]
triangle[row][col] += max(right, left) # 두 κ°’ 쀑 더 큰 κ°’

answer = max(triangle[-1])
return answer
49 changes: 49 additions & 0 deletions LJEDD2/2024-2/완전탐색/ν”Όλ‘œλ„..py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 첫 번째 μ½”λ“œ
def solution(k, dungeons):

def DFS(k, cnt):
nonlocal answer

answer = max(answer, cnt)
for i in range(len(dungeons)):
# λ˜μ „ = ["μ΅œμ†Œ ν•„μš” ν”Όλ‘œλ„", "μ†Œλͺ¨ ν”Όλ‘œλ„"]
min_fatigue, use_fatigue = dungeons[i][0], dungeons[i][1]

# ν˜„μž¬ ν”Όλ‘œλ„κ°€ ν•΄λ‹Ή λ˜μ „μ„ λ°©λ¬Έν•˜κΈ° μœ„ν•œ μ΅œμ†Œ ν”Όλ‘œλ„λ³΄λ‹€ 클 λ•Œ
if not visited[i] and k >= min_fatigue:
visited[i] = True

# λ°±νŠΈλž˜ν‚Ή : 이전 λ…Έλ“œλ‘œ λ‹€μ‹œ backν•  λ•Œ,
# ν•΄λ‹Ή λ…Έλ“œλ₯Ό λ°©λ¬Έν•˜κΈ° μ „μ˜ ν”Όλ‘œλ„λ‘œ λ‹€μ‹œ 볡ꡬ
DFS(k-use_fatigue, cnt+1)
visited[i] = False

answer = 0
visited = [False] * len(dungeons) # visited
DFS(k, 0)

return answer


# κ°œμ„ λœ μ½”λ“œ
def solution(k, dungeons):
def dfs(k, cnt):
# ν•¨μˆ˜ λ‚΄λΆ€μ—μ„œ 값을 κ°±μ‹ ν•  수 μžˆλŠ” λΉ„μ „μ—­ λ³€μˆ˜λ‘œ μ„ μ–Έ
nonlocal answer

answer = max(answer, cnt)

# enumerate()λ₯Ό ν™œμš©ν•˜μ—¬ 각 λ˜μ „μ˜ μΈλ±μŠ€μ™€ 값을 λ™μ‹œμ— 반볡
for i, (min_fatigue, use_fatigue) in enumerate(dungeons):

if not visited[i] and k >= min_fatigue:

visited[i] = True
dfs(k - use_fatigue, cnt + 1)
visited[i] = False

answer = 0
visited = [False] * len(dungeons)
dfs(k, 0)

return answer