From adeda9d03801fecd88014f401f982ce56daa3245 Mon Sep 17 00:00:00 2001 From: Minjeong Kim Date: Wed, 16 Jul 2025 01:38:23 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[PGS]=20=ED=83=80=EA=B2=9F=EB=84=98?= =?UTF-8?q?=EB=B2=84=20/=20Level=202=20/=2030=EB=B6=84=20/=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...62\237\353\204\230\353\262\204(java).java" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "minjeong/DFSBFS/2025-07-14-[PGS]-\355\203\200\352\262\237\353\204\230\353\262\204(java).java" diff --git "a/minjeong/DFSBFS/2025-07-14-[PGS]-\355\203\200\352\262\237\353\204\230\353\262\204(java).java" "b/minjeong/DFSBFS/2025-07-14-[PGS]-\355\203\200\352\262\237\353\204\230\353\262\204(java).java" new file mode 100644 index 0000000..6c1fbc0 --- /dev/null +++ "b/minjeong/DFSBFS/2025-07-14-[PGS]-\355\203\200\352\262\237\353\204\230\353\262\204(java).java" @@ -0,0 +1,19 @@ +class Solution { + int count = 0; + + public int solution(int[] numbers, int target) { + backtracking(0, 0, numbers, target); + + return count; + } + + public void backtracking(int idx, int currSum, int[] numbers, int target) { + if (idx == numbers.length) { + if (currSum == target) count++; + return; + } + + backtracking(idx + 1, currSum + numbers[idx], numbers, target); + backtracking(idx + 1, currSum - numbers[idx], numbers, target); + } +} \ No newline at end of file From 85103d7d9af243663b6d8a278bad18fe1e8db9c8 Mon Sep 17 00:00:00 2001 From: Minjeong Kim Date: Thu, 17 Jul 2025 21:06:37 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[BOJ]=20#15683.=20=EA=B0=90=EC=8B=9C=20/=20?= =?UTF-8?q?=EA=B3=A8=EB=93=9C=203=20/=201=EC=8B=9C=EA=B0=84=20/=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\200]-#15683-\352\260\220\354\213\234.py" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "minjeong/Backtracking/2025-07-21-[\353\260\261\354\244\200]-#15683-\352\260\220\354\213\234.py" diff --git "a/minjeong/Backtracking/2025-07-21-[\353\260\261\354\244\200]-#15683-\352\260\220\354\213\234.py" "b/minjeong/Backtracking/2025-07-21-[\353\260\261\354\244\200]-#15683-\352\260\220\354\213\234.py" new file mode 100644 index 0000000..4a01774 --- /dev/null +++ "b/minjeong/Backtracking/2025-07-21-[\353\260\261\354\244\200]-#15683-\352\260\220\354\213\234.py" @@ -0,0 +1,69 @@ +import sys +import copy + +input = sys.stdin.readline + +N, M = map(int, input().split()) +office = [list(map(int, input().split())) for _ in range(N)] + +# CCTV 위치 저장 +cctvs = [] +for i in range(N): + for j in range(M): + if 1 <= office[i][j] <= 5: + cctvs.append((i, j, office[i][j])) + +total_cctv = len(cctvs) # 전체 CCTV 개수 +min_blind_spot = 1e9 # 정답으로 반환할 사각지대 개수 + +# CCTV별 방향 설정 +directions = [(-1, 0), (0, 1), (1, 0), (0, -1)] # 상 -> 우 -> 하 -> 좌 +cctv_dirs = { + 1: [[0], [1], [2], [3]], + 2: [[0, 2], [1, 3]], + 3: [[0, 1], [1, 2], [2, 3], [3, 0]], + 4: [[0, 1, 2], [1, 2, 3], [2, 3, 0], [3, 0, 1]], + 5: [[0, 1, 2, 3]] +} + + +# 사각지대 개수 구하는 함수 +def count_zero(temp): + cnt = 0 + for i in range(N): + for j in range(M): + if temp[i][j] == 0: + cnt += 1 + return cnt + + +# DFS 함수 +def dfs(idx, office): + global min_blind_spot + # 종료 조건 + if idx == total_cctv: + # 종료할 때는 사각지대(= 0) 개수 세고, 최소값 갱신해야 한다. + blind_spot = count_zero(office) + min_blind_spot = min(min_blind_spot, blind_spot) + return + + x, y, number = cctvs[idx] + for cctv_dir in cctv_dirs[number]: + # temp에 현재 office 리스트 깊은 복사 + temp = copy.deepcopy(office) + + for dir in cctv_dir: + dx, dy = directions[dir] + nx, ny = x + dx, y + dy + + while 0 <= nx < N and 0 <= ny < M and temp[nx][ny] != 6: + if temp[nx][ny] == 0: + temp[nx][ny] = '#' # CCTV 감시OK + nx += dx + ny += dy + + dfs(idx + 1, temp) + + +dfs(0, office) +print(min_blind_spot) \ No newline at end of file From d6b92e3196ee52958d92b2422ca069038804a1d4 Mon Sep 17 00:00:00 2001 From: Minjeong Kim Date: Sat, 19 Jul 2025 21:08:35 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[PGS]=20=EA=B2=8C=EC=9E=84=20=EB=A7=B5=20?= =?UTF-8?q?=EC=B5=9C=EB=8B=A8=EA=B1=B0=EB=A6=AC=20/=20Level=202=20/=2030?= =?UTF-8?q?=EB=B6=84=20/=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...13\250\352\261\260\353\246\254(java).java" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "minjeong/DFSBFS/2025-07-18-[PGS]-\352\262\214\354\236\204\353\247\265\354\265\234\353\213\250\352\261\260\353\246\254(java).java" diff --git "a/minjeong/DFSBFS/2025-07-18-[PGS]-\352\262\214\354\236\204\353\247\265\354\265\234\353\213\250\352\261\260\353\246\254(java).java" "b/minjeong/DFSBFS/2025-07-18-[PGS]-\352\262\214\354\236\204\353\247\265\354\265\234\353\213\250\352\261\260\353\246\254(java).java" new file mode 100644 index 0000000..74888b4 --- /dev/null +++ "b/minjeong/DFSBFS/2025-07-18-[PGS]-\352\262\214\354\236\204\353\247\265\354\265\234\353\213\250\352\261\260\353\246\254(java).java" @@ -0,0 +1,44 @@ +import java.util.*; + +class Solution { + public int solution(int[][] maps) { + int n = maps.length; + int m = maps[0].length; + + // 방문여부 리스트 + boolean[][] visited = new boolean[n][m]; + visited[0][0] = true; + + // 방향 벡터 만들기 + int[][] dirs ={{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; + + // 큐 선언 + Queue queue = new LinkedList<>(); + queue.offer(new int[]{0, 0}); + + // BFS 탐색 + while (!queue.isEmpty()) { + int[] current = queue.poll(); + int x = current[0]; + int y = current[1]; + + for (int[] dir : dirs) { + int nx = x + dir[0]; + int ny = y + dir[1]; + + if ((0 <= nx && nx < n && 0 <= ny && ny < m) + && !visited[nx][ny] + && maps[nx][ny] == 1) { + maps[nx][ny] = maps[x][y] + 1; + visited[nx][ny] = true; + queue.add(new int[]{nx, ny}); + } + } + } + + if (maps[n-1][m-1] != 1) { + return maps[n-1][m-1]; + } + return -1; + } +} \ No newline at end of file From fc26fb1fb288d1b13ff0833dfd474a78cbfe8a99 Mon Sep 17 00:00:00 2001 From: Minjeong Kim Date: Tue, 22 Jul 2025 21:55:49 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[BOJ]=20#16987.=20=EA=B3=84=EB=9E=80?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=B9=98=EA=B8=B0=20/=20=EA=B3=A8?= =?UTF-8?q?=EB=93=9C5=20/=201=EC=8B=9C=EA=B0=84=20/=20=ED=9E=8C=ED=8A=B8,?= =?UTF-8?q?=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\353\236\200\354\271\230\352\270\260.py" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "minjeong/Backtracking/2025-07-22-[\353\260\261\354\244\200]-#16987-\352\263\204\353\236\200\354\234\274\353\241\234\352\263\204\353\236\200\354\271\230\352\270\260.py" diff --git "a/minjeong/Backtracking/2025-07-22-[\353\260\261\354\244\200]-#16987-\352\263\204\353\236\200\354\234\274\353\241\234\352\263\204\353\236\200\354\271\230\352\270\260.py" "b/minjeong/Backtracking/2025-07-22-[\353\260\261\354\244\200]-#16987-\352\263\204\353\236\200\354\234\274\353\241\234\352\263\204\353\236\200\354\271\230\352\270\260.py" new file mode 100644 index 0000000..cb04648 --- /dev/null +++ "b/minjeong/Backtracking/2025-07-22-[\353\260\261\354\244\200]-#16987-\352\263\204\353\236\200\354\234\274\353\241\234\352\263\204\353\236\200\354\271\230\352\270\260.py" @@ -0,0 +1,56 @@ +import sys + +input = sys.stdin.readline + +N = int(input()) # 계란의 수 +eggs = [list(map(int, input().split())) for _ in range(N)] # 계란의 내구도와 무게를 담은 리스트 + +max_broken = 0 # 최대 깨진 계란 수를 저장하는 변수 + + +def count_broken_eggs(eggs): + # 깨진 계란의 수 구하기 + count = 0 + for S, W in eggs: + if S <= 0: + count += 1 + return count + + +def dfs(cur_idx): + global max_broken + # 모든 계란을 한 번씩 든 경우 + if cur_idx == N: + # 깨진 계란의 수 세고 max_broken 갱신 + max_broken = max(max_broken, count_broken_eggs(eggs)) + return + + # 현재 계란이 깨졌다면 다음 계란으로 넘어간다. + if eggs[cur_idx][0] <= 0: + dfs(cur_idx + 1) + return + + broken = False # 현재 계란으로 다른 계란을 깼는지 여부 + for i in range(N): + if i == cur_idx or eggs[i][0] <= 0: + continue + + # 계란끼리 치기 + eggs[cur_idx][0] -= eggs[i][1] + eggs[i][0] -= eggs[cur_idx][1] + broken = True + + # 탐색 + dfs(cur_idx + 1) # 다음 계란으로 넘어간다. + + # 상태 복구 + eggs[cur_idx][0] += eggs[i][1] + eggs[i][0] += eggs[cur_idx][1] + + # 칠 수 있는 계란이 없었던 경우, 다음으로 넘어가야 한다. + if not broken: + dfs(cur_idx + 1) + + +dfs(0) +print(max_broken) \ No newline at end of file