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

9 ljedd2 #156

Merged
merged 13 commits into from
Oct 17, 2024
6 changes: 5 additions & 1 deletion LJEDD2/2024-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
| 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) |
| 8μ°¨μ‹œ | 2024.09.04 | μœ„μƒμ •λ ¬ | <a href="https://www.acmicpc.net/problem/1766">λ¬Έμ œμ§‘</a> | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/154) |
| 9μ°¨μ‹œ | 2024.09.07 | μŠ€νƒ | <a href="https://www.acmicpc.net/problem/2176">μ›μˆ­μ΄ 맀달기</a> | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) |
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 더 κ°„λ‹¨ν•œ 풀이 ... (λ¬Έμžμ—΄)
import sys
input = sys.stdin.readline

for _ in range(int(input())):
cnt = 0
s = input().rstrip()
while "[]" in s:
s = s.replace("[]", "")
cnt += 1

print(2**cnt)



# import sys

# input = sys.stdin.readline

# for _ in range(int(input())):
# s = input().rstrip() # κ΄„ν˜Έ λ¬Έμžμ—΄

# max_depth = 0 # μ΅œλŒ€ 깊이λ₯Ό μ €μž₯ν•  λ³€μˆ˜
# tree = list() # ν˜„μž¬ μ—΄λ¦° κ΄„ν˜Έλ₯Ό μ €μž₯ν•  μŠ€νƒμž„

# for i in s:
# # μ—¬λŠ” κ΄„ν˜ΈμΌ 경우 μŠ€νƒμ— μ—΄λ¦° κ΄„ν˜Έ μΆ”κ°€
# if i == '[':
# tree.append('[')
# continue
# # λ‹«λŠ” κ΄„ν˜ΈμΌ 경우
# max_depth = max(len(tree), max_depth)
# # ν˜„μž¬ κΉŠμ΄μ™€ μ΅œλŒ€ 깊이 쀑 큰 값을 μ €μž₯ν•˜κ³ 
# tree.pop() # λ§ˆμ§€λ§‰ μ—΄λ¦° κ΄„ν˜Έλ₯Ό 제거

# print(2 ** max_depth) # μŒμ„ μ΄λ£°λ•Œ 가지 생성, 가지2-.1κ°œμ”© λ‚˜λˆ κ°€μ§
# # κ²°κ΅­μ—” 2의 depth승
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
33 changes: 33 additions & 0 deletions LJEDD2/2024-2/μœ„μƒμ •λ ¬/λ¬Έμ œμ§‘.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# BOJ1766 λ¬Έμ œμ§‘
# μœ„μƒμ •λ ¬ + μš°μ„ μˆœμœ„ 큐

import heapq

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)
indegree[e] += 1 # μ§„μž… 차수 데이터 μ €μž₯

# λ¬Έμ œμ—μ„œ κ°€λŠ₯ν•œ μ•ž 번호의 λ¬Έμ œλΆ€ν„° ν’€μ–΄μ•Ό 함 -> μš°μ„ μˆœμœ„ν,,?
# 1~N의 λ‚œμ΄λ„ 순 λŒ€λ‘œ

queue = []

# μˆœμ„œ
for i in range(1, n + 1):
if indegree[i] == 0:
heapq.heappush(queue, i) # μ§„μž…μ°¨μˆ˜κ°€ 0인거 λ¨Όμ € λ‚œμ΄λ„λž‘ μ €μž₯

while queue:
now = heapq.heappop(queue)
print(now, end=' ')

for i in graph[now]: # μœ„μƒ μ •λ ¬ μˆ˜ν–‰ , μ§„μž… 차수 μ—†μ• !
indegree[i] -= 1

if indegree[i] == 0:
heapq.heappush(queue, i)
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)