Skip to content

Commit 50081d2

Browse files
committed
[BOJ] #1759. 암호 만들기 / 골드1 / 50분 / 힌트
1 parent bcd4d65 commit 50081d2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
L, C = map(int, input().split()) # L: 암호 길이, C: 문자 종류
5+
chars = sorted(input().split()) # 사전순 정렬
6+
vowels = {'a', 'e', 'i', 'o', 'u'}
7+
8+
9+
def is_valid(word):
10+
# 최소 한 개의 모음과 최소 두 개의 자음으로 구성되어있는지 확인
11+
vowel_cnt, consonant_cnt = 0, 0 # 모음 개수, 자음 개수
12+
for w in word:
13+
if w in vowels:
14+
vowel_cnt += 1
15+
else:
16+
consonant_cnt += 1
17+
18+
return vowel_cnt >= 1 and consonant_cnt >= 2
19+
20+
21+
def backtrack(word, start):
22+
if len(word) == L: # 종료 조건
23+
if is_valid(word):
24+
print(''.join(word))
25+
return
26+
27+
for i in range(start, C):
28+
word.append(chars[i])
29+
backtrack(word, i+1)
30+
word.pop()
31+
32+
backtrack([], 0)

0 commit comments

Comments
 (0)