From 283eebe6d5357a31bc1e488426f6febd0cb7e363 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Thu, 1 Aug 2024 01:53:05 +0900 Subject: [PATCH 1/4] =?UTF-8?q?2024-07-31=20=EC=A0=95=EC=88=98=20=EC=82=BC?= =?UTF-8?q?=EA=B0=81=ED=98=95.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...210\230 \354\202\274\352\260\201\355\230\225.py" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "LJEDD2/2024-2/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/\354\240\225\354\210\230 \354\202\274\352\260\201\355\230\225.py" diff --git "a/LJEDD2/2024-2/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/\354\240\225\354\210\230 \354\202\274\352\260\201\355\230\225.py" "b/LJEDD2/2024-2/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/\354\240\225\354\210\230 \354\202\274\352\260\201\355\230\225.py" new file mode 100644 index 0000000..74c9f45 --- /dev/null +++ "b/LJEDD2/2024-2/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/\354\240\225\354\210\230 \354\202\274\352\260\201\355\230\225.py" @@ -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 \ No newline at end of file From cd7997b423697ec7ff3abaec254f6c132952e8a4 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Thu, 1 Aug 2024 01:56:09 +0900 Subject: [PATCH 2/4] 2024-07-31 --- LJEDD2/2024-2/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LJEDD2/2024-2/README.md b/LJEDD2/2024-2/README.md index 08556df..262f09b 100644 --- a/LJEDD2/2024-2/README.md +++ b/LJEDD2/2024-2/README.md @@ -5,4 +5,6 @@ | 1차시 | 2024.07.17 | 이분탐색 | 입국심사 | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/123) | | 2차시 | 2024.07.20 | 다이나믹프로그래밍 | N으로 표현 | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/126) | | 3차시 | 2024.07.24 | 깊이/너비 우선 탐색(DFS/BFS) | 여행경로 | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/131) | +| 4차시 | 2024.07.27 | 그래프 | 가장 먼 노드 | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/133) | +| 5차시 | 2024.07.31 | 다이나믹프로그래밍 | 정수 삼각형 | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/139) | --- \ No newline at end of file From 4f20884858d5a17e1fe428f390e6515c7267121f Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Sat, 3 Aug 2024 23:36:55 +0900 Subject: [PATCH 3/4] =?UTF-8?q?2024-08-03=20=ED=94=BC=EB=A1=9C=EB=8F=84.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\224\274\353\241\234\353\217\204..py" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "LJEDD2/2024-2/\354\231\204\354\240\204\355\203\220\354\203\211/\355\224\274\353\241\234\353\217\204..py" diff --git "a/LJEDD2/2024-2/\354\231\204\354\240\204\355\203\220\354\203\211/\355\224\274\353\241\234\353\217\204..py" "b/LJEDD2/2024-2/\354\231\204\354\240\204\355\203\220\354\203\211/\355\224\274\353\241\234\353\217\204..py" new file mode 100644 index 0000000..da273b4 --- /dev/null +++ "b/LJEDD2/2024-2/\354\231\204\354\240\204\355\203\220\354\203\211/\355\224\274\353\241\234\353\217\204..py" @@ -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 \ No newline at end of file From 9ed98a6b1279a852bcebef699f396b44802fe5cf Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Sat, 3 Aug 2024 23:38:23 +0900 Subject: [PATCH 4/4] 2024-08-03 --- LJEDD2/2024-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/LJEDD2/2024-2/README.md b/LJEDD2/2024-2/README.md index 2feff67..1dd7f96 100644 --- a/LJEDD2/2024-2/README.md +++ b/LJEDD2/2024-2/README.md @@ -7,3 +7,4 @@ | 3차시 | 2024.07.24 | 깊이/너비 우선 탐색(DFS/BFS) | 여행경로 | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/131) | | 4차시 | 2024.07.27 | 그래프 | 가장 먼 노드 | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/133) | | 5차시 | 2024.07.31 | 다이나믹프로그래밍 | 정수 삼각형 | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/139) | +| 6차시 | 2024.08.03 | 완전탐색 | 피로도 | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/141) |