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

BOJ 2529 - ๋ถ€๋“ฑํ˜ธ

by HandHand 2021. 3. 8.

๋ฌธ์ œ

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

ํ’€์ด ๊ณผ์ •

๋ถ€๋“ฑํ˜ธ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ์ตœ์†Œ ๋ฐ ์ตœ๋Œ€ ์ˆ˜์—ด์„ ์ฐพ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

๋ฐฑํŠธ๋ž˜ํ‚น ์„ ํ™œ์šฉํ•ด์„œ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ๋ชจ๋“  ์ˆ˜์—ด์„ ์ƒ์„ฑํ•œ ๋‹ค์Œ ์ตœ๋Œ€ ๋ฐ ์ตœ์†Œ ๊ฐ’์„ ๋น„๊ตํ•ด์„œ ๋‹ต์„ ๊ตฌํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ


import sys

K = int(input())
signs = list(sys.stdin.readline().split())
min_value = '9999999999'
max_value = '0'


def compare(pick):
    global min_value, max_value

    num = ''.join(map(str, pick))
    min_value = min_value if int(min_value) < int(num) else num
    max_value = max_value if int(max_value) > int(num) else num


def dfs(pick, depth):
    if depth == K:
        compare(pick)
        return

    for num in range(10):
        if num not in pick:
            if signs[depth] == '<' and num <= pick[depth]:
                continue
            elif signs[depth] == '>' and num >= pick[depth]:
                continue

            pick.append(num)
            dfs(pick, depth + 1)
            pick.pop()


def solution():
    for start in range(10):
        dfs([start], 0)

    print(max_value)
    print(min_value)


solution()
๋ฐ˜์‘ํ˜•

'๐Ÿƒ algorithm > boj' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

BOJ 9184 - ์‹ ๋‚˜๋Š” ํ•จ์ˆ˜ ์‹คํ–‰  (0) 2021.03.08
BOJ 14226 - ์ด๋ชจํ‹ฐ์ฝ˜  (0) 2021.03.08
BOJ 1802 - ์ข…์ด ์ ‘๊ธฐ  (0) 2021.03.08
BOJ 17829 - 222-ํ’€๋ง  (0) 2021.03.08
BOJ 13905 - ์„ธ๋ถ€  (0) 2021.03.08

๐Ÿ’ฌ ๋Œ“๊ธ€