파이썬 조합을 이용해 푸는 방법
from itertools import combinations
L, C = map(int, input().split())
alp = list(map(str, input().split()))
alp.sort()
for i in list(map(''.join, combinations(alp, L))):
ja, mo = 0, 0
for j in i:
if j in 'aeiou':
mo += 1
else:
ja += 1
if ja >= 2 and mo >= 1:
print(i)
재귀로 푸는 방법
L, C = map(int, input().split())
alp = list(map(str, input().split()))
alp.sort()
def check(pw):
ja, mo = 0, 0
for i in range(len(pw)):
if pw[i] in 'aeiou':
mo += 1
else:
ja += 1
return ja >= 2 and mo >= 1
def recur(depth, prev_selc_str):
if len(prev_selc_str) == L:
if check(prev_selc_str):
print(prev_selc_str)
return
if depth >= C:
return
recur(depth+1, prev_selc_str+alp[depth])
recur(depth+1, prev_selc_str)
recur(0, '')