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

7 ljedd2 #152

Merged
merged 8 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
4 changes: 3 additions & 1 deletion LJEDD2/2024-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
| 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) |
| 7μ°¨μ‹œ | 2024.09.01 | μœ„μƒμ •λ ¬ | <a href="https://www.acmicpc.net/problem/2252">쀄 μ„Έμš°κΈ°</a> | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/152) |
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# BOJ2252 쀄 μ„Έμš°κΈ°
from collections import deque

n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
indegree = [0] * (n + 1) # μ§„μž… 차수 μ €μž₯ν•  리슀트

for i in range(m):
s,e = map(int, input().split())
graph[s].append(e) # zz
indegree[e] += 1 # μ§„μž… 차수 데이터λ₯Ό μ €μž₯

# Bλ₯Ό ν•˜κΈ° μœ„ν•΄ AλΌλŠ” μž‘μ—…μ„ λ¨Όμ € ν•΄μ•Ό ν•˜λŠ” ꡬ쑰가 μžˆμ„ λ•Œ,
# κ·Έ μž‘μ—… μˆœμ„œλ₯Ό κ΅¬ν•΄μ£ΌλŠ” 것 = μœ„μƒμ •λ ¬

queue = deque()
for i in range(1, n + 1):
if not indegree[i]:
queue.append(i)

while queue: # μœ„μƒ μ •λ ¬ μˆ˜ν–‰ , μ§„μž… 차수 μ—†μ• !
now = queue.popleft()
print(now, end=' ')

for next in graph[now]:
indegree[next] -= 1 # μ§„μž… 차수 0인 정점 큐에 μ‚½μž…
if not indegree[next]:
queue.append(next)