-
Notifications
You must be signed in to change notification settings - Fork 5
Minjeong / 4월 3주차 / 4문제 #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50081d2
[BOJ] #1759. 암호 만들기 / 골드1 / 50분 / 힌트
Mingguriguri 5398244
[BOJ] #6603. 로또 / 실버2 / 20분 / 성공
Mingguriguri 89c726b
fix: #6603. 로또 문제 풀이 날짜 변경
Mingguriguri 839fc00
[BOJ] #9084. 동전 / 골드5 / 120분 / 힌트, 성공
Mingguriguri a74e1a5
[BOJ] #1053. 팰린드롬 공장 / 골드1 / 120분 / 실패
Mingguriguri 97f454c
WeeklyChallenge: WeeklyChallenge 과제 문제(#6603. 로또) 정답 코드 추가
Mingguriguri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |
32 changes: 32 additions & 0 deletions
32
minjeong/DynamicProgramming/2025-04-14-[백준]-#1759-암호만들기.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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]) |
52 changes: 52 additions & 0 deletions
52
minjeong/DynamicProgramming/2025-04-18-[백준]-#1053-팰린드롬공장.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.