From 50081d2204780be01f1e4c84128e5d7fa3ff2891 Mon Sep 17 00:00:00 2001 From: Minjeong Kim <101111603+Mingguriguri@users.noreply.github.com> Date: Mon, 14 Apr 2025 23:48:07 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[BOJ]=20#1759.=20=EC=95=94=ED=98=B8=20?= =?UTF-8?q?=EB=A7=8C=EB=93=A4=EA=B8=B0=20/=20=EA=B3=A8=EB=93=9C1=20/=2050?= =?UTF-8?q?=EB=B6=84=20/=20=ED=9E=8C=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...70\353\247\214\353\223\244\352\270\260.py" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "minjeong/DynamicProgramming/2025-04-14-[\353\260\261\354\244\200]-#1759-\354\225\224\355\230\270\353\247\214\353\223\244\352\270\260.py" diff --git "a/minjeong/DynamicProgramming/2025-04-14-[\353\260\261\354\244\200]-#1759-\354\225\224\355\230\270\353\247\214\353\223\244\352\270\260.py" "b/minjeong/DynamicProgramming/2025-04-14-[\353\260\261\354\244\200]-#1759-\354\225\224\355\230\270\353\247\214\353\223\244\352\270\260.py" new file mode 100644 index 0000000..a6eb092 --- /dev/null +++ "b/minjeong/DynamicProgramming/2025-04-14-[\353\260\261\354\244\200]-#1759-\354\225\224\355\230\270\353\247\214\353\223\244\352\270\260.py" @@ -0,0 +1,32 @@ +import sys +input = sys.stdin.readline + +L, C = map(int, input().split()) # L: 암호 길이, C: 문자 종류 +chars = sorted(input().split()) # 사전순 정렬 +vowels = {'a', 'e', 'i', 'o', 'u'} + + +def is_valid(word): + # 최소 한 개의 모음과 최소 두 개의 자음으로 구성되어있는지 확인 + vowel_cnt, consonant_cnt = 0, 0 # 모음 개수, 자음 개수 + for w in word: + if w in vowels: + vowel_cnt += 1 + else: + consonant_cnt += 1 + + return vowel_cnt >= 1 and consonant_cnt >= 2 + + +def backtrack(word, start): + if len(word) == L: # 종료 조건 + if is_valid(word): + print(''.join(word)) + return + + for i in range(start, C): + word.append(chars[i]) + backtrack(word, i+1) + word.pop() + +backtrack([], 0) From 53982446e8e662b2790e5972572286605b411c7d Mon Sep 17 00:00:00 2001 From: Minjeong Kim <101111603+Mingguriguri@users.noreply.github.com> Date: Tue, 15 Apr 2025 18:25:31 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[BOJ]=20#6603.=20=EB=A1=9C=EB=98=90=20/=20?= =?UTF-8?q?=EC=8B=A4=EB=B2=842=20/=2020=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 --- ...0\355\202\271\355\222\200\354\235\264).py" | 28 +++++++++++++++++++ ...0\355\225\251\355\222\200\354\235\264).py" | 19 +++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 "minjeong/Backtracking/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\353\260\261\355\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" create mode 100644 "minjeong/Combinatorics/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" diff --git "a/minjeong/Backtracking/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\353\260\261\355\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" "b/minjeong/Backtracking/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\353\260\261\355\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" new file mode 100644 index 0000000..604434d --- /dev/null +++ "b/minjeong/Backtracking/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\353\260\261\355\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" @@ -0,0 +1,28 @@ +import sys +input = sys.stdin.readline + +""" +#6603. 로또 +백트래킹 풀이 +""" + +def backtrack(lotto, current): + if len(lotto) == 6: # 종료조건 + print(' '.join(map(str, lotto))) + return + + for i in range(current, k): + lotto.append(S[i]) + backtrack(lotto, i+1) + lotto.pop() + + +while True: + testcase = input().strip() + if testcase == '0': + break + nums = list(map(int, testcase.split())) + k, S = nums[0], nums[1:] + + backtrack([], 0) + print() diff --git "a/minjeong/Combinatorics/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" "b/minjeong/Combinatorics/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" new file mode 100644 index 0000000..0c69232 --- /dev/null +++ "b/minjeong/Combinatorics/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" @@ -0,0 +1,19 @@ +import sys +from itertools import combinations +input = sys.stdin.readline + +""" +#6603. 로또 +조합 풀이 +""" + +while True: + testcase = input().strip() + if testcase == '0': + break + nums = list(map(int, testcase.split())) + k, S = nums[0], nums[1:] + combs = list(combinations(S, 6)) + for comb in combs: + print(' '.join(map(str, comb))) + print() \ No newline at end of file From 89c726b28f788116119fd955199c5f5e2db6d5c8 Mon Sep 17 00:00:00 2001 From: Minjeong Kim <101111603+Mingguriguri@users.noreply.github.com> Date: Thu, 17 Apr 2025 14:58:52 +0900 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20#6603.=20=EB=A1=9C=EB=98=90=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=92=80=EC=9D=B4=20=EB=82=A0=EC=A7=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" | 0 ...\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename "minjeong/Backtracking/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\353\260\261\355\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" => "minjeong/Backtracking/2025-04-16-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\353\260\261\355\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" (100%) rename "minjeong/Combinatorics/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" => "minjeong/Combinatorics/2025-04-16-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" (100%) diff --git "a/minjeong/Backtracking/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\353\260\261\355\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" "b/minjeong/Backtracking/2025-04-16-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\353\260\261\355\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" similarity index 100% rename from "minjeong/Backtracking/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\353\260\261\355\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" rename to "minjeong/Backtracking/2025-04-16-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\353\260\261\355\212\270\353\236\230\355\202\271\355\222\200\354\235\264).py" diff --git "a/minjeong/Combinatorics/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" "b/minjeong/Combinatorics/2025-04-16-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" similarity index 100% rename from "minjeong/Combinatorics/2025-04-14-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" rename to "minjeong/Combinatorics/2025-04-16-[\353\260\261\354\244\200]-#6603-\353\241\234\353\230\220(\354\241\260\355\225\251\355\222\200\354\235\264).py" From 839fc005fec42d549bcbf96a1dab57966905f63a Mon Sep 17 00:00:00 2001 From: Minjeong Kim <101111603+Mingguriguri@users.noreply.github.com> Date: Thu, 17 Apr 2025 17:24:33 +0900 Subject: [PATCH 4/6] =?UTF-8?q?[BOJ]=20#9084.=20=EB=8F=99=EC=A0=84=20/=20?= =?UTF-8?q?=EA=B3=A8=EB=93=9C5=20/=20120=EB=B6=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 --- ...\244\200]-#9084-\353\217\231\354\240\204.py" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "minjeong/DynamicProgramming/2025-04-17-[\353\260\261\354\244\200]-#9084-\353\217\231\354\240\204.py" diff --git "a/minjeong/DynamicProgramming/2025-04-17-[\353\260\261\354\244\200]-#9084-\353\217\231\354\240\204.py" "b/minjeong/DynamicProgramming/2025-04-17-[\353\260\261\354\244\200]-#9084-\353\217\231\354\240\204.py" new file mode 100644 index 0000000..0b68860 --- /dev/null +++ "b/minjeong/DynamicProgramming/2025-04-17-[\353\260\261\354\244\200]-#9084-\353\217\231\354\240\204.py" @@ -0,0 +1,17 @@ +import sys +input = sys.stdin.readline + +T = int(input()) +for _ in range(T): + N = int(input()) # 동전의 가지 수 + coins = list(map(int, input().split())) # N가지 동전의 각 금액 + M = int(input()) # 목표 금액 + + dp = [0] * (M+1) + dp[0] = 1 + + for coin in coins: + for i in range(coin, M + 1): + dp[i] += dp[i - coin] + + print(dp[M]) \ No newline at end of file From a74e1a575ae987730a0b563ae2c09875b460fb29 Mon Sep 17 00:00:00 2001 From: Minjeong Kim <101111603+Mingguriguri@users.noreply.github.com> Date: Fri, 18 Apr 2025 23:24:08 +0900 Subject: [PATCH 5/6] =?UTF-8?q?[BOJ]=20#1053.=20=ED=8C=B0=EB=A6=B0?= =?UTF-8?q?=EB=93=9C=EB=A1=AC=20=EA=B3=B5=EC=9E=A5=20/=20=EA=B3=A8?= =?UTF-8?q?=EB=93=9C1=20/=20120=EB=B6=84=20/=20=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\353\241\254\352\263\265\354\236\245.py" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "minjeong/DynamicProgramming/2025-04-18-[\353\260\261\354\244\200]-#1053-\355\214\260\353\246\260\353\223\234\353\241\254\352\263\265\354\236\245.py" diff --git "a/minjeong/DynamicProgramming/2025-04-18-[\353\260\261\354\244\200]-#1053-\355\214\260\353\246\260\353\223\234\353\241\254\352\263\265\354\236\245.py" "b/minjeong/DynamicProgramming/2025-04-18-[\353\260\261\354\244\200]-#1053-\355\214\260\353\246\260\353\223\234\353\241\254\352\263\265\354\236\245.py" new file mode 100644 index 0000000..b60e463 --- /dev/null +++ "b/minjeong/DynamicProgramming/2025-04-18-[\353\260\261\354\244\200]-#1053-\355\214\260\353\246\260\353\223\234\353\241\254\352\263\265\354\236\245.py" @@ -0,0 +1,52 @@ +import sys +input = sys.stdin.readline + + +def min_ops_to_pal(s): + """ + s: list of chars + return: 최소 편집 연산(삽입, 삭제, 교체만 허용)으로 s를 팰린드롬으로 만드는 비용 + """ + n = len(s) + # dp[i][j]: s[i..j]를 팰린드롬으로 만드는 최소 연산 횟수 + dp = [[0] * n for _ in range(n)] + # 길이 2부터 n까지 늘려가며 + for length in range(2, n + 1): + for i in range(n - length + 1): + j = i + length - 1 + if s[i] == s[j]: + dp[i][j] = dp[i + 1][j - 1] + else: + # 교체(대칭 맞추기), 삭제(왼쪽), 삭제(오른쪽) + dp[i][j] = min( + dp[i + 1][j - 1] + 1, + dp[i + 1][j] + 1, + dp[i][j - 1] + 1 + ) + for d in dp: + print(d) + + return dp[0][n - 1] if n > 0 else 0 + + +s = list(input().rstrip()) +n = len(s) + +# 1. 교환 없이 삽입/삭제/교체만 사용했을 때 +ans = min_ops_to_pal(s) +if ans <= 1: + print(ans) + exit() + +# 2. 서로 다른 문자끼리 한 번만 교환을 허용해봤을 때, 교환 비용 1을 더해보고 개선되는지 확인 +for i in range(n): + for j in range(i + 1, n): + if s[i] != s[j]: + # 문자가 같지 않은 경우, SWAP + s[i], s[j] = s[j], s[i] + swap_cost = min_ops_to_pal(s) + 1 # swap 비용 포함 + if swap_cost < ans: # swap한 경우가 더 작다면 ans에 업데이트 + ans = swap_cost + # 복구 + s[i], s[j] = s[j], s[i] +print(ans) From 97f454c20d09c12c4fd9a03377d9bd2d024841ac Mon Sep 17 00:00:00 2001 From: Minjeong Kim <101111603+Mingguriguri@users.noreply.github.com> Date: Sat, 19 Apr 2025 23:44:10 +0900 Subject: [PATCH 6/6] =?UTF-8?q?WeeklyChallenge:=20WeeklyChallenge=20?= =?UTF-8?q?=EA=B3=BC=EC=A0=9C=20=EB=AC=B8=EC=A0=9C(#6603.=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90)=20=EC=A0=95=EB=8B=B5=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ment_BOJ_6603_\353\241\234\353\230\220.py" | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git "a/_WeeklyChallenges/W19-[Graph-Backtracking]/Assignment_BOJ_6603_\353\241\234\353\230\220.py" "b/_WeeklyChallenges/W19-[Graph-Backtracking]/Assignment_BOJ_6603_\353\241\234\353\230\220.py" index 818569d..80e17b1 100644 --- "a/_WeeklyChallenges/W19-[Graph-Backtracking]/Assignment_BOJ_6603_\353\241\234\353\230\220.py" +++ "b/_WeeklyChallenges/W19-[Graph-Backtracking]/Assignment_BOJ_6603_\353\241\234\353\230\220.py" @@ -4,4 +4,49 @@ 유형: Graph, Backtracking """ -# 토요일에 업로드 예정 \ No newline at end of file +""" +#6603. 로또 +백트래킹 풀이 +""" +import sys +input = sys.stdin.readline +def backtrack(lotto, current): + if len(lotto) == 6: # 종료조건 + print(' '.join(map(str, lotto))) + return + + for i in range(current, k): + lotto.append(S[i]) + backtrack(lotto, i+1) + lotto.pop() + + +while True: + testcase = input().strip() + if testcase == '0': + break + nums = list(map(int, testcase.split())) + k, S = nums[0], nums[1:] + + backtrack([], 0) + print() + + +""" +#6603. 로또 +조합 풀이 +""" +import sys +from itertools import combinations +input = sys.stdin.readline + +while True: + testcase = input().strip() + if testcase == '0': + break + nums = list(map(int, testcase.split())) + k, S = nums[0], nums[1:] + combs = list(combinations(S, 6)) + for comb in combs: + print(' '.join(map(str, comb))) + print() \ No newline at end of file