문제풀이/DFS & BFS

[파이썬] [DFS] 백준 1759 암호 만들기

승무_ 2022. 5. 27. 19:36

문제

https://www.acmicpc.net/problem/1759

 

1759번: 암호 만들기

첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.

www.acmicpc.net

코드

def dfs(i,len):
    if len == l:
        vo=0
        co=0
        for j in range(l):
            if result[j] in 'aeiou': vo += 1
            else: co+=1
        if vo>=1 and co>=2:
            print("".join(result))
        return
    for m in range(i, c):
        if check[m]==0:
            result.append(array[m])
            check[m]=1
            dfs(m + 1,len+1)
            check[m]=0
            del result[-1]

l, c = map(int, input().split())
array = input().split()
array.sort()

check = [0 for i in range(c)]
result = []
dfs(0,0)