Skip to content

Commit

Permalink
2024-05-26
Browse files Browse the repository at this point in the history
  • Loading branch information
H0ngJu committed May 26, 2024
1 parent 3fa8bfb commit 6cfc099
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions H0ngJu/DFS/계란으로 계란치기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys
sys.setrecursionlimit(10**6)

def input(): return sys.stdin.readline().rstrip()

N = int(input())
eggs = [list(map(int, input().split())) for _ in range(N)]

def break_egg(idx):
cnt = 0

# idx가 넘어간 경우
if idx == N:
for i in range(N):
if eggs[i][0] <= 0:
cnt += 1
return cnt

if eggs[idx][0] <= 0: # 들고 있는 계란이 깨진 경우
return break_egg(idx+1)

broken = False
for j in range(N): # 계란 깨기
if j != idx and eggs[j][0] > 0:
broken = True
eggs[idx][0] -= eggs[j][1]
eggs[j][0] -= eggs[idx][1]

cnt = max(cnt, break_egg(idx+1))

eggs[idx][0] += eggs[j][1]
eggs[j][0] += eggs[idx][1]

if not broken:
return break_egg(idx+1)

return cnt

print(break_egg(0))
1 change: 1 addition & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
| 15차시 | 2024.05.14 | 그리디 | [A와 B](https://www.acmicpc.net/problem/12904) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/188 |
| 16차시 | 2024.05.14 | BFS | [뱀과 사다리 게임](https://www.acmicpc.net/problem/16928) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/191 |
| 17차시 | 2024.05.22 | BFS | [적록색약](https://www.acmicpc.net/problem/10026) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/195 |
| 17차시 | 2024.05.26 | DFS | [계란으로 계란치기](https://www.acmicpc.net/problem/16987) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/199 |

---

0 comments on commit 6cfc099

Please sign in to comment.