๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿƒ algorithm/boj

BOJ 13908 - ๋น„๋ฐ€๋ฒˆํ˜ธ

by HandHand 2021. 4. 13.

๋ฌธ์ œ

๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€ - 13908๋ฒˆ

ํ’€์ด ๊ณผ์ •

๋น„๋ฐ€๋ฒˆํ˜ธ์— ํฌํ•จ๋œ ์ˆซ์ž๋“ค์„ ์•Œ๊ณ  ์žˆ์„ ๋•Œ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์ฐพ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.
๋ฐฑํŠธ๋ž˜ํ‚น ์„ ์ด์šฉํ•ด์„œ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋”ฐ์ ธ๋ณธ ๋‹ค์Œ, ์ƒ์„ฑ๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•˜๋Š”์ง€ ํŒ๋‹จํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ


import sys


def is_valid(password):
    return all(map(lambda num: num in password, nums))


def dfs(password):
    if len(password) == n:
        return 1 if is_valid(password) else 0

    ret = 0
    for i in range(10):
        password.append(i)
        ret += dfs(password)
        password.pop()

    return ret


def solution():
    answer = dfs([])

    return answer


if __name__ == '__main__':
    n, m = list(map(int, sys.stdin.readline().split()))
    nums = list(map(int, sys.stdin.readline().split())) if m != 0 else []

    answer = solution()
    print(answer)
๋ฐ˜์‘ํ˜•

๐Ÿ’ฌ ๋Œ“๊ธ€