ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

2210๋ฒˆ: ์ˆซ์žํŒ ์ ํ”„

111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111, 121112, 121211, 121212, 211111, 211121, 212111, 212121 ์ด ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ๋“ค์ด๋‹ค.

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

 5x5 ํฌ๊ธฐ์˜ ์ˆซ์žํŒ์ด ์žˆ์„ ๋•Œ, ์ž„์˜์˜ ์œ„์น˜์—์„œ ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ์ธ์ ‘ํ•ด ์žˆ๋Š” ๋„ค ๋ฐฉํ–ฅ์œผ๋กœ ๋‹ค์„ฏ ๋ฒˆ ์ด๋™ํ•˜๋ฉด์„œ, ๊ฐ ์นธ์— ์ ํ˜€์žˆ๋Š” ์ˆซ์ž๋ฅผ ์ฐจ๋ก€๋กœ ๋ถ™์ด๋ฉด 6์ž๋ฆฌ์˜ ์ˆ˜๊ฐ€ ๋œ๋‹ค. ์ด๋•Œ ์„œ๋กœ ๋‹ค๋ฅธ ์—ฌ์„ฏ ์ž๋ฆฌ์˜ ์ˆ˜๋“ค์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ๋‹ต์„ ์ฐพ๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐ ๊ทธ๋ž˜ํ”„์˜ ์ขŒํ‘œ๋งˆ๋‹ค DFS๋ฅผ ํ†ตํ•ด, ๋ฐฉ๋ฌธ๊ฐ€๋Šฅํ•œ ๊ฒฝ๋กœ๋ฅผ ํƒ์ƒ‰ํ•˜๊ณ  6์ž๋ฆฌ๊ฐ€ ๋˜๋ฉด ์ˆซ์ž๋ฅผ ๊ธฐ๋กํ•˜๋ฉด ์‰ฝ๊ฒŒ ๋ฌธ์ œ๋ฅผ ํ’€ ์ˆ˜ ์žˆ๋‹ค.

 

์ฝ”๋“œ

from sys import stdin


def dfs(x, y, num):

    if len(num) == 6:
        answer.add(num)
        return

    for dx, dy in dirs:
        next_x, next_y = x + dx, y + dy

        if 0 <= next_x < 5 and 0 <= next_y < 5:
            dfs(next_x, next_y, num + graph[next_x][next_y])


if __name__ == '__main__':
    answer = set()
    dirs = ((0, 1), (0, -1), (1, 0), (-1, 0))
    graph = [list(stdin.readline().split()) for _ in range(5)]

    for i in range(5):
        for j in range(5):
            dfs(i, j, '')
    print(len(answer))
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€