From 2075a0b078d58b67ae994852ba5eeb2029dd7f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Thu, 7 Sep 2023 22:24:40 +0900 Subject: [PATCH 01/15] =?UTF-8?q?[BOJ]=20=EB=B3=B4=EB=AC=BC=20/=20?= =?UTF-8?q?=EC=8B=A4=EB=B2=84=204=20/=2010=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1026 \353\263\264\353\254\274.py" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "mingsound/Backjoon/\352\267\270\353\246\254\353\224\224/1026 \353\263\264\353\254\274.py" diff --git "a/mingsound/Backjoon/\352\267\270\353\246\254\353\224\224/1026 \353\263\264\353\254\274.py" "b/mingsound/Backjoon/\352\267\270\353\246\254\353\224\224/1026 \353\263\264\353\254\274.py" new file mode 100644 index 0000000..b3a1946 --- /dev/null +++ "b/mingsound/Backjoon/\352\267\270\353\246\254\353\224\224/1026 \353\263\264\353\254\274.py" @@ -0,0 +1,15 @@ +import sys +input = sys.stdin.readline + +n = int(input()) +A = list(map(int, input().split())) +B = list(map(int, input().split())) + +A.sort() +B.sort(reverse=True) + +answer = 0 +for i in range(n): + answer += A[i] * B[i] + +print(answer) From 9af137a4cec5cedbd462e137537c9bed7f9b6f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Thu, 7 Sep 2023 22:52:21 +0900 Subject: [PATCH 02/15] =?UTF-8?q?[BOJ*]=20=ED=8F=89=EB=B2=94=ED=95=9C=20?= =?UTF-8?q?=EB=B0=B0=EB=82=AD=20/=20=EA=B3=A8=EB=93=9C=205=20/=2010?= =?UTF-8?q?=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\225\234 \353\260\260\353\202\255.py" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "mingsound/Backjoon/DP/12865 \355\217\211\353\262\224\355\225\234 \353\260\260\353\202\255.py" diff --git "a/mingsound/Backjoon/DP/12865 \355\217\211\353\262\224\355\225\234 \353\260\260\353\202\255.py" "b/mingsound/Backjoon/DP/12865 \355\217\211\353\262\224\355\225\234 \353\260\260\353\202\255.py" new file mode 100644 index 0000000..ff0395f --- /dev/null +++ "b/mingsound/Backjoon/DP/12865 \355\217\211\353\262\224\355\225\234 \353\260\260\353\202\255.py" @@ -0,0 +1,20 @@ +import sys +input = sys.stdin.readline + +n, k = map(int, input().split()) # 물건 수, 버틸 수 있는 무게 +arr = [(0, 0)] + [tuple(list(map(int, input().split()))) for _ in range(n)] # (무게, 가치) + +dp = [[0] * (k+1) for _ in range(n+1)] # dp[i][j]는 i번째 물건까지 봤을때, 견딜 수 있는 무게가 j인 경우 최대 value + +for i in range(1, n+1): + weight, value = arr[i] + for j in range(1, k+1): + # 새로 추가될 물건의 무게가, 견딜 수 있는 무게보다 크다면, 이전 물건까지의 값을 이어 받는다. + if weight > j: + dp[i][j] = dp[i-1][j] + else: + # 새로운 물건을 담아 value를 얻는 것과 이전 물건까지 계산했던 value 중에서 더 큰 것을 택함 + dp[i][j] = max(dp[i-1][j-weight] + value, dp[i-1][j]) + +print(dp[n][k]) + From 9222c0b27978953b1e96be751a3af205397e7d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Fri, 8 Sep 2023 01:06:13 +0900 Subject: [PATCH 03/15] =?UTF-8?q?[BOJ*]=20=ED=9C=B4=EA=B2=8C=EC=86=8C=20?= =?UTF-8?q?=EC=84=B8=EC=9A=B0=EA=B8=B0=20/=20=EA=B3=A8=EB=93=9C=204=20/=20?= =?UTF-8?q?25=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\204\270\354\232\260\352\270\260.py" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "mingsound/Backjoon/\354\235\264\353\266\204\355\203\220\354\203\211/1477 \355\234\264\352\262\214\354\206\214 \354\204\270\354\232\260\352\270\260.py" diff --git "a/mingsound/Backjoon/\354\235\264\353\266\204\355\203\220\354\203\211/1477 \355\234\264\352\262\214\354\206\214 \354\204\270\354\232\260\352\270\260.py" "b/mingsound/Backjoon/\354\235\264\353\266\204\355\203\220\354\203\211/1477 \355\234\264\352\262\214\354\206\214 \354\204\270\354\232\260\352\270\260.py" new file mode 100644 index 0000000..ac63c44 --- /dev/null +++ "b/mingsound/Backjoon/\354\235\264\353\266\204\355\203\220\354\203\211/1477 \355\234\264\352\262\214\354\206\214 \354\204\270\354\232\260\352\270\260.py" @@ -0,0 +1,29 @@ +import sys +input = sys.stdin.readline + +N, M, L = map(int, input().split()) +arr = [0] + list(map(int, input().split())) + [L] + + +start, end = 1, L-1 +result = 0 +while start <= end: + count = 0 + mid = (start + end) // 2 # 가장 멀리 떨어져있는 휴게소 사이 거리 + for i in range(1, len(arr)): + # 현재 거리 중에서 mid보다 큰 거리를 찾아서 + if arr[i] - arr[i-1] > mid: + count += (arr[i] - arr[i-1] - 1) // mid + + if count > M: # 목표보다 너무 많이 설치했다면, 멀리 떨어져있는 휴게소 사이 거리 늘리기 + start = mid + 1 + else: # 예비 정답 + end = mid - 1 + result = mid + +print(result) + +# 이분탐색 - 파라메트릭 서치 +# 최적화 문제(문제의 상황을 만족하는 특정 변수의 최소, 최대값을 구하는 문제)를 결정 문제로 바꾸어 푸는것 +# 범위 내에서 조건을 만족하는 가장 큰 값을 찾으라는 최적화 문제의 경우 전형적인 파라메트릭 서치 +# 이분탐색으로 풀 수 있는 문제라는 것을 파악조차 못함 From 93904b1e193ad99abc65155b94a10bcad56e1dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Fri, 8 Sep 2023 10:39:08 +0900 Subject: [PATCH 04/15] =?UTF-8?q?[BOJ]=20=EB=8B=A4=EB=A6=AC=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EA=B8=B0=20/=20=EA=B3=A8=EB=93=9C=203=20/=2060?= =?UTF-8?q?=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \353\247\214\353\223\244\352\270\260.py" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "mingsound/Backjoon/BFS/2146 \353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" diff --git "a/mingsound/Backjoon/BFS/2146 \353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" "b/mingsound/Backjoon/BFS/2146 \353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" new file mode 100644 index 0000000..e804f2d --- /dev/null +++ "b/mingsound/Backjoon/BFS/2146 \353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" @@ -0,0 +1,69 @@ +import sys +input = sys.stdin.readline +from collections import deque + +n = int(input()) +graph = [list(map(int, input().split())) for _ in range(n)] + + +dx = [-1, 1, 0, 0] +dy = [0, 0, -1, 1] +# 각 섬 구분 +def color_bfs(x, y, idx): + deq = deque([(x, y)]) + deq2 = deque([(x, y)]) # 섬의 모든 좌표를 담은 deque + graph[x][y] = idx + + while deq: + x, y = deq.popleft() + + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + if 0 <= nx < n and 0 <= ny < n and graph[nx][ny] == 1: + graph[nx][ny] = idx + deq.append((nx, ny)) + deq2.append((nx, ny)) + + return bfs(deq2, idx) + + +# 해당 섬에서 다른 섬까지의 가장 짧은 좌표 +def bfs(deq2, idx): + deq = deq2 + x, y = deq2[0] + visited = [[0] * n for _ in range(n)] + visited[x][y] = 1 + answer = sys.maxsize + + while deq: + x, y = deq.popleft() + + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + if 0 <= nx < n and 0 <= ny < n and not visited[nx][ny]: # 범위 안에 있고, 아직 방문하지 않았다면 + if graph[nx][ny] == idx: # 같은 섬이라면 visited 1로 처리(방문표시만 하고, 거리는 증가 X) + visited[nx][ny] = 1 # + deq.append((nx, ny)) + elif graph[nx][ny] == 0: # 물이라면, visited에 거리를 +1한 값을 작성 + visited[nx][ny] = visited[x][y] + 1 + deq.append((nx, ny)) + else: # 다른섬을 만났다면, answer 더 작은 값으로 갱신 + answer = min(answer, visited[x][y]-1) + return answer + +# 섬 구분 +idx = 2 +answer = sys.maxsize +for i in range(n): + for j in range(n): + if graph[i][j] == 1: + answer = min(answer, color_bfs(i, j, idx)) + idx += 1 + +print(answer) + + From 7f1e78d2fbf019af40d2dfc45b9235bbd7796544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Fri, 8 Sep 2023 11:14:20 +0900 Subject: [PATCH 05/15] =?UTF-8?q?[BOJ*]=20=EC=88=A8=EB=B0=94=EA=BC=AD?= =?UTF-8?q?=EC=A7=88=203=20/=20=EA=B3=A8=EB=93=9C=205=20/=2015=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\260\224\352\274\255\354\247\210 3.py" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "mingsound/Backjoon/BFS/13549 \354\210\250\353\260\224\352\274\255\354\247\210 3.py" diff --git "a/mingsound/Backjoon/BFS/13549 \354\210\250\353\260\224\352\274\255\354\247\210 3.py" "b/mingsound/Backjoon/BFS/13549 \354\210\250\353\260\224\352\274\255\354\247\210 3.py" new file mode 100644 index 0000000..0a58a91 --- /dev/null +++ "b/mingsound/Backjoon/BFS/13549 \354\210\250\353\260\224\352\274\255\354\247\210 3.py" @@ -0,0 +1,36 @@ +import sys +input = sys.stdin.readline +from collections import deque + +n, k = map(int, input().split()) +MAX = 100001 +visited = [False] * MAX +dist = [-1] * MAX + +q = deque() +q.append(n) +visited[n] = True +dist[n] = 0 + +dx = [-1, 1] +while q: + now = q.popleft() + if now == k: # 목표 도달 + break + + next = now * 2 + if 0 <= next < MAX and not visited[next]: + q.appendleft(next) # 우선순위가 높으니까 왼쪽 + visited[next] = True + dist[next] = dist[now] + + for i in range(2): + next = now + dx[i] + if 0 <= next < MAX and not visited[next]: + q.append(next) + visited[next] = True + dist[next] = dist[now] + 1 + +print(dist[k]) + +# 우선순위에 따라서 왼쪽에 넣을수가 있군 \ No newline at end of file From ef283816cf8024101165e1a91b0716823e558a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Fri, 8 Sep 2023 14:34:21 +0900 Subject: [PATCH 06/15] =?UTF-8?q?[BOJ*]=20=EB=A7=90=EC=9D=B4=20=EB=90=98?= =?UTF-8?q?=EA=B3=A0=ED=94=88=20=EC=9B=90=EC=88=AD=EC=9D=B4=20/=20?= =?UTF-8?q?=EA=B3=A8=EB=93=9C=203=20/=2040=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\233\220\354\210\255\354\235\264.py" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "mingsound/Backjoon/BFS/1600 \353\247\220\354\235\264 \353\220\230\352\263\240\355\224\210 \354\233\220\354\210\255\354\235\264.py" diff --git "a/mingsound/Backjoon/BFS/1600 \353\247\220\354\235\264 \353\220\230\352\263\240\355\224\210 \354\233\220\354\210\255\354\235\264.py" "b/mingsound/Backjoon/BFS/1600 \353\247\220\354\235\264 \353\220\230\352\263\240\355\224\210 \354\233\220\354\210\255\354\235\264.py" new file mode 100644 index 0000000..f6cb8fc --- /dev/null +++ "b/mingsound/Backjoon/BFS/1600 \353\247\220\354\235\264 \353\220\230\352\263\240\355\224\210 \354\233\220\354\210\255\354\235\264.py" @@ -0,0 +1,41 @@ +import sys +input = sys.stdin.readline +from collections import deque + + +k = int(input()) +w, h = map(int, input().split()) +graph = [list(map(int, input().split())) for _ in range(h)] +visited = [[[0] * w for _ in range(h)] for _ in range(k+1)] +# print(len(visited), len(visited[0]), len(visited[0][0])) +dx = [-1, 1, 0, 0] +dy = [0, 0, -1, 1] +dx2 = [-1, -1, -2, -2, 1, 1, 2, 2] +dy2 = [-2, 2, -1, 1, -2, 2, -1, 1] + +deq = deque([(0, 0, 0)]) # (x, y, cnt) +visited[0][0][0] = 1 + +while deq: + x, y, cnt = deq.popleft() + + if x == h-1 and y == w-1: + print(visited[cnt][x][y]-1) + exit(0) + + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + if 0 <= nx < h and 0 <= ny < w and not visited[cnt][nx][ny] and graph[nx][ny] == 0: + visited[cnt][nx][ny] = visited[cnt][x][y] + 1 + deq.append((nx, ny, cnt)) + + if cnt < k: + for i in range(8): + nx = x + dx2[i] + ny = y + dy2[i] + if 0 <= nx < h and 0 <= ny < w and not visited[cnt+1][nx][ny] and graph[nx][ny] == 0: + visited[cnt+1][nx][ny] = visited[cnt][x][y] + 1 + deq.append((nx, ny, cnt+1)) + +print(-1) \ No newline at end of file From f5053cf58a0fbe7c41675cc94e3ac4ccbe2a9a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Fri, 8 Sep 2023 15:17:57 +0900 Subject: [PATCH 07/15] =?UTF-8?q?[BOJ*]=20=EC=88=A8=EB=B0=94=EA=BC=AD?= =?UTF-8?q?=EC=A7=88=204=20/=20=EA=B3=A8=EB=93=9C=204=20/=2040=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\260\224\352\274\255\354\247\210 4.py" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "mingsound/Backjoon/BFS/13913 \354\210\250\353\260\224\352\274\255\354\247\210 4.py" diff --git "a/mingsound/Backjoon/BFS/13913 \354\210\250\353\260\224\352\274\255\354\247\210 4.py" "b/mingsound/Backjoon/BFS/13913 \354\210\250\353\260\224\352\274\255\354\247\210 4.py" new file mode 100644 index 0000000..76a667f --- /dev/null +++ "b/mingsound/Backjoon/BFS/13913 \354\210\250\353\260\224\352\274\255\354\247\210 4.py" @@ -0,0 +1,41 @@ +import sys +input = sys.stdin.readline +from collections import deque + +n, k = map(int, input().split()) + +visited = [-1] * 100001 + + +def bfs(): + + deq = deque([(n, 0)]) + visited[n] = n + + while deq: + now, cnt = deq.popleft() + + if now == k: + return cnt + + next = now * 2 + if 0 <= next < 100001 and visited[next] == -1 and next != 0: + visited[next] = now # 방문처리 대신, 이전에 방문한 위치를 저장 + deq.append((next, cnt + 1)) + + for dx in [-1, 1]: + next = now + dx + if 0 <= next < 100001 and visited[next] == -1: + visited[next] = now + deq.append((next, cnt + 1)) + + +print(bfs()) + +route = [k] +while k != n: + route.append(visited[k]) + k = visited[k] +print(*route[::-1]) + +# https://www.acmicpc.net/board/view/125156 <- 메모리 초과 해결... From e99b43c926a1f4fd3ab7c35c514c9c69b1924095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Fri, 8 Sep 2023 16:00:06 +0900 Subject: [PATCH 08/15] =?UTF-8?q?[BOJ]=20=EB=B2=BD=20=EB=B6=80=EC=88=98?= =?UTF-8?q?=EA=B3=A0=20=EC=9D=B4=EB=8F=99=ED=95=98=EA=B8=B0=202=20/=20?= =?UTF-8?q?=EA=B3=A8=EB=93=9C=203=20/=2020=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\217\231\355\225\230\352\270\260 2.py" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "mingsound/Backjoon/BFS/14442 \353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260 2.py" diff --git "a/mingsound/Backjoon/BFS/14442 \353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260 2.py" "b/mingsound/Backjoon/BFS/14442 \353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260 2.py" new file mode 100644 index 0000000..f6b8d46 --- /dev/null +++ "b/mingsound/Backjoon/BFS/14442 \353\262\275 \353\266\200\354\210\230\352\263\240 \354\235\264\353\217\231\355\225\230\352\270\260 2.py" @@ -0,0 +1,41 @@ +import sys +input = sys.stdin.readline +from collections import deque + +n, m, k = map(int, input().split()) +graph = [list(map(int, list(input().rstrip()))) for _ in range(n)] +visited = [[[0] * m for _ in range(n)] for _ in range(k+1)] +# print(len(visited), len(visited[0]), len(visited[0][0])) +dx = [-1, 1, 0, 0] +dy = [0, 0, -1, 1] + +def bfs(): + deq = deque([(0, 0, 0)]) # (x, y, cnt) + visited[0][0][0] = 1 + + while deq: + x, y, cnt = deq.popleft() + + if x == n-1 and y == m-1: # 원하는 위치에 도달 + return visited[cnt][x][y] + + + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + if 0 <= nx < n and 0 <= ny < m: # 격자 범위 안에 들어오는 경우에 대해서만 + # 다음 이동 칸이 벽이 아닌 경우 + if graph[nx][ny] == 0: + + if not visited[cnt][nx][ny]: + visited[cnt][nx][ny] = visited[cnt][x][y] + 1 + deq.append((nx, ny, cnt)) + # 다음 이동 칸이 벽인 경우 + else: + if cnt < k and not visited[cnt+1][nx][ny]: # 아직 벽을 부술 수 있는 경우 + visited[cnt+1][nx][ny] = visited[cnt][x][y] + 1 + deq.append((nx, ny, cnt+1)) + + return -1 + +print(bfs()) \ No newline at end of file From 40017abcb8384e9eef3c373008430120f94272de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:32:53 +0900 Subject: [PATCH 09/15] =?UTF-8?q?[BOJ*]=20N=EA=B3=BC=20M(1)=20/=20?= =?UTF-8?q?=EC=8B=A4=EB=B2=84=203=20/=2010=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../N\352\263\274 M(1).py" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(1).py" diff --git "a/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(1).py" "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(1).py" new file mode 100644 index 0000000..9cae7c9 --- /dev/null +++ "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(1).py" @@ -0,0 +1,20 @@ +def dfs(): + if len(s) == m: # m개를 모두 택했다면 + print(' '.join(map(str, s))) # 출력 + return + + # 백트래킹 핵심 구조 + for i in range(1, n+1): + if visited[i]:# 아직 i가 사용되지 않았다면 + continue # 계속 + visited[i] = True + s.append(i) + dfs() # 다음 수를 고르러 한 단계 더 들어감 + s.pop() # 백 트래킹, 다 확인했으니까 마지막꺼 + visited[i] = False + +n, m = map(int, input().split()) +s = [] +visited = [False] * (n+1) + +dfs() \ No newline at end of file From fcc3812ff2a125dcc23f5d56b3abe37e1bd242be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:42:58 +0900 Subject: [PATCH 10/15] =?UTF-8?q?[BOJ]=20N=EA=B3=BC=20M(2)=20/=20=EC=8B=A4?= =?UTF-8?q?=EB=B2=84=203=20/=2010=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../N\352\263\274 M(2).py" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(2).py" diff --git "a/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(2).py" "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(2).py" new file mode 100644 index 0000000..72e1c66 --- /dev/null +++ "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(2).py" @@ -0,0 +1,23 @@ +def dfs(): + if len(s) == m: + print(" ".join(list(map(str, s)))) + return + + for i in range(1, n+1): + if visited[i]: + continue + if len(s) != 0 and s[-1] > i: # s가 비어있지 않은데, 가장 마지막에 있는 것보다 작으면, 오름차순 아님 + continue + + visited[i] = True + s.append(i) + dfs() + s.pop() + visited[i] = False + + +n, m = map(int, input().split()) +s = [] +visited = [False] * (n+1) + +dfs() \ No newline at end of file From 88c18d0dcb1bd8ae733fd17728d3df77d2685d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:44:29 +0900 Subject: [PATCH 11/15] =?UTF-8?q?[BOJ]=20N=EA=B3=BC=20M(3)=20/=20=EC=8B=A4?= =?UTF-8?q?=EB=B2=84=203=20/=205=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../N\352\263\274 M(3).py" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(3).py" diff --git "a/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(3).py" "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(3).py" new file mode 100644 index 0000000..44d05f1 --- /dev/null +++ "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(3).py" @@ -0,0 +1,15 @@ +def dfs(): + if len(s) == m: + print(" ".join(list(map(str, s)))) + return + + for i in range(1, n+1): + s.append(i) + dfs() + s.pop() + + +n, m = map(int, input().split()) +s = [] + +dfs() \ No newline at end of file From f34b38bf5a4739a09757e807bee58241577add53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:46:19 +0900 Subject: [PATCH 12/15] =?UTF-8?q?[BOJ]=20N=EA=B3=BC=20M(4)=20/=20=EC=8B=A4?= =?UTF-8?q?=EB=B2=84=203=20/=205=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../N\352\263\274 M(4).py" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(4).py" diff --git "a/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(4).py" "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(4).py" new file mode 100644 index 0000000..e2e053a --- /dev/null +++ "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(4).py" @@ -0,0 +1,18 @@ +def dfs(): + if len(s) == m: + print(" ".join(list(map(str, s)))) + return + + for i in range(1, n+1): + if len(s) != 0 and s[-1] > i: # s가 비어있지 않은데, 가장 마지막에 있는 것보다 작으면, 오름차순 아님 + continue + + s.append(i) + dfs() + s.pop() + + +n, m = map(int, input().split()) +s = [] + +dfs() \ No newline at end of file From b4f1b0e2f7a3dae29259aba62c8987a8b0b33328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:49:29 +0900 Subject: [PATCH 13/15] =?UTF-8?q?[BOJ]=20N=EA=B3=BC=20M(5)=20/=20=EC=8B=A4?= =?UTF-8?q?=EB=B2=84=203=20/=205=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../N\352\263\274 M(5).py" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(5).py" diff --git "a/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(5).py" "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(5).py" new file mode 100644 index 0000000..13f4a84 --- /dev/null +++ "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(5).py" @@ -0,0 +1,21 @@ +def dfs(): + if len(s) == m: + print(' '.join(map(str, s))) + return + + # 백트래킹 핵심 구조 + for i in range(n): + if visited[i]: + continue + visited[i] = True + s.append(arr[i]) + dfs() + s.pop() + visited[i] = False + +n, m = map(int, input().split()) +arr = sorted(list(map(int, input().split()))) +s = [] +visited = [False] * (n+1) + +dfs() \ No newline at end of file From e45418409318f702fda2b1757f71e808570a31ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Tue, 12 Sep 2023 01:01:02 +0900 Subject: [PATCH 14/15] =?UTF-8?q?[BOJ]=20N=EA=B3=BC=20M(6)=20/=20=EC=8B=A4?= =?UTF-8?q?=EB=B2=84=203=20/=2015=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../N\352\263\274 M(6).py" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(6).py" diff --git "a/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(6).py" "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(6).py" new file mode 100644 index 0000000..21d8b7e --- /dev/null +++ "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(6).py" @@ -0,0 +1,31 @@ +def dfs(): + if len(s) == m: + print(' '.join(map(str, s))) + return + + # 백트래킹 핵심 구조 + for i in range(n): + if visited[i]: + continue + + if len(s) != 0 and s[-1] > arr[i]: # s가 비어있지 않은데, 가장 마지막에 있는 것보다 작으면, 오름차순 아님 + continue + + visited[i] = True + s.append(arr[i]) + dfs() + s.pop() + visited[i] = False + +n, m = map(int, input().split()) +arr = sorted(list(map(int, input().split()))) +s = [] +visited = [False] * (n) + +for i in range(n): + visited[i] = True + s.append(arr[i]) + + dfs() + s.pop() + visited[i] = False From 149c2e3a4faf1c7166405f3e2a0d9c5a42bd1b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A0=95?= <62479120+mingsound21@users.noreply.github.com> Date: Tue, 12 Sep 2023 01:02:41 +0900 Subject: [PATCH 15/15] =?UTF-8?q?[BOJ]=20N=EA=B3=BC=20M(7)=20/=20=EC=8B=A4?= =?UTF-8?q?=EB=B2=84=203=20/=205=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../N\352\263\274 M(7).py" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(7).py" diff --git "a/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(7).py" "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(7).py" new file mode 100644 index 0000000..65353b0 --- /dev/null +++ "b/mingsound/Backjoon/\353\260\261\355\212\270\353\236\230\355\202\271/N\352\263\274 M(7).py" @@ -0,0 +1,21 @@ +def dfs(): + if len(s) == m: + print(' '.join(map(str, s))) + return + + # 백트래킹 핵심 구조 + for i in range(n): + s.append(arr[i]) + dfs() + s.pop() + + +n, m = map(int, input().split()) +arr = sorted(list(map(int, input().split()))) +s = [] + +for i in range(n): + s.append(arr[i]) + dfs() + s.pop() +