Skip to content

Commit 52d3dea

Browse files
authored
Merge pull request #195 from AlgorithmStudy-Allumbus/learntosurf
Rebase ์˜ค๋ฅ˜,,,
2 parents 3d01744 + d4ac27b commit 52d3dea

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

โ€Ž.gitignoreโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.cph/
22
.DS_Store
3-
.DS_Store
3+
.vscode/

โ€Ž.vscode/settings.jsonโ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"github.copilot.enable": {
3+
"*": false,
4+
"plaintext": false,
5+
"markdown": false,
6+
"scminput": false
7+
}
8+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sys
2+
input = sys.stdin.readline
3+
from itertools import combinations
4+
5+
L, C = map(int, input().split())
6+
chars = input().split()
7+
chars.sort() # ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
8+
9+
vowels = set('aeiou')
10+
result = []
11+
12+
# ๋ฐฑํŠธ๋ž˜ํ‚น: ํ•ด๋ฅผ ์ฐพ๋Š” ๋„์ค‘ ํ•ด๊ฐ€ ์•„๋‹ˆ์–ด์„œ ๋ง‰ํžˆ๋ฉด, ๋˜๋Œ์•„๊ฐ€์„œ ๋‹ค์‹œ ํ•ด๋ฅผ ์ฐพ์•„๊ฐ€๋Š” ๊ธฐ๋ฒ•
13+
# ํ˜„์žฌ๊นŒ์ง€ ๋งŒ๋“  ์•”ํ˜ธ์˜ ๊ธธ์ด๊ฐ€ L์ด๋ฉด ์ข…๋ฃŒ ์กฐ๊ฑด
14+
# ๋ชจ์Œ/์ž์Œ ๊ฐœ์ˆ˜๋ฅผ ์ฒดํฌํ•ด์„œ ๋งŒ์กฑํ•  ๊ฒฝ์šฐ ์ถœ๋ ฅ
15+
# ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๋‹ค์Œ ์•ŒํŒŒ๋ฒณ์„ ์„ ํƒํ•ด ์žฌ๊ท€ ํ˜ธ์ถœ
16+
def backtrack(path, start):
17+
# 1. ์ข…๋ฃŒ ์กฐ๊ฑด: ๊ธธ์ด๊ฐ€ L์ด๋ฉด ์กฐํ•ฉ ์™„์„ฑ
18+
if len(path) == L:
19+
vowel_count = 0
20+
consonant_count = 0
21+
22+
# ๋ชจ์Œ/์ž์Œ ๊ฐœ์ˆ˜ ์„ธ๊ธฐ
23+
for ch in path:
24+
if ch in vowels:
25+
vowel_count += 1
26+
else:
27+
consonant_count += 1
28+
29+
# ์กฐ๊ฑด์— ๋งž์œผ๋ฉด ์ถœ๋ ฅ
30+
if vowel_count >= 1 and consonant_count >= 2:
31+
print(''.join(path))
32+
return
33+
34+
# 2. ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๋ฌธ์ž์— ๋Œ€ํ•ด ์„ ํƒ
35+
for i in range(start, C): # C == len(chars)
36+
# ์„ ํƒ
37+
path.append(chars[i])
38+
# ์žฌ๊ท€ ํ˜ธ์ถœ(๋‹ค์Œ ๋ฌธ์ž ์„ ํƒ) - ์กฐํ•ฉ์ด๋ฏ€๋กœ i+1๋ถ€ํ„ฐ
39+
backtrack(path, i+1)
40+
# ์„ ํƒ ์ทจ์†Œ
41+
path.pop()
42+
43+
# ํƒ์ƒ‰ ์‹œ์ž‘
44+
backtrack([], 0)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
input = sys.stdin.readline
3+
from itertools import combinations
4+
5+
L, C = map(int, input().split())
6+
chars = input().split()
7+
chars.sort() # ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
8+
9+
candidates = list(combinations(chars, L)) # L๊ฐœ ๊ณ ๋ฅด๋Š” ๋ชจ๋“  ์กฐํ•ฉ์„ ์ƒ์„ฑ
10+
11+
# ์กฐ๊ฑด์— ๋งž๋Š” ์กฐํ•ฉ ํ•„ํ„ฐ๋ง
12+
# ์กฐ๊ฑด: ๋ชจ์Œ >= 1๊ฐœ, ์ž์Œ >= 2๊ฐœ
13+
vowels = set('aeiou')
14+
15+
for comb in candidates:
16+
vowel_count = 0
17+
consonant_count = 0
18+
19+
for ch in comb:
20+
if ch in vowels:
21+
vowel_count += 1
22+
else:
23+
consonant_count += 1
24+
25+
if vowel_count >= 1 and consonant_count >= 2:
26+
print(''.join(comb))

0 commit comments

Comments
ย (0)