BOJ - 1759 - 암호 만들기

Updated:

import sys

con = ["a", "e", "i", "o", "u"]

def DFS(start, check, word, L, C, count):
    # print(start, check, word, L, C, count)
    if count == L:
        ret = ""
        for i in range(C):
            if check[i]:
                ret += word[i]

        conCnt = 0
        for i in range(len(ret)):
            if ret[i] in con:
                conCnt += 1

        if len(ret) - conCnt >= 2 and conCnt:
            print(ret)

        return

    for idx in range(start + 1, C):
        check[idx] = True
        DFS(idx, check, word, L, C, count+1)
        check[idx] = False

def solution():
    L, C = map(int, sys.stdin.readline().split())
    word = list(map(str, sys.stdin.readline().split()))
    word.sort()

    check = [False for _ in range(C)]
    for idx in range(C):
        check[idx] = True
        DFS(idx, check, word, L, C, 1)
        check[idx] = False


solution()

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

Categories:

Updated:

Leave a comment