[BOJ] 14712. ๋„ด๋ชจ๋„ด๋ชจ (Easy) (๐Ÿฅ‡, ๋ฐฑํŠธ๋ž˜ํ‚น)

lemythe423ยท2023๋…„ 9์›” 15์ผ
0

BOJ ๋ฌธ์ œํ’€์ด

๋ชฉ๋ก ๋ณด๊ธฐ
48/133
post-thumbnail

๐Ÿ”—

ํ’€์ด

๋ชจ๋“  ์นธ์€ ๋„ด๋ชจ๋ฅผ ๋†“๊ฑฐ๋‚˜ ๋†“์ง€ ์•Š๋Š” 2๊ฐ€์ง€ ๊ฒฝ์šฐ๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ๋‹ค. 2x2 ํ˜•ํƒœ์˜ ๋„ด๋ชจ๊ฐ€ ์ด๋ค„์ง€์ง€ ์•Š๋„๋ก ์œ„์ชฝ ์™ผ์ชฝ๋ถ€ํ„ฐ ์˜ค๋ฅธ์ชฝ ์•„๋ž˜์ชฝ๊นŒ์ง€ ์ฐจ๋ก€๋Œ€๋กœ ํƒ์ƒ‰ํ•œ๋‹ค. ๋„์ค‘์— 2x2๋ฅผ ์ด๋ฃจ๊ฒŒ ๋œ๋‹ค๋ฉด ๋ฐฑํŠธ๋ž˜ํ‚น์œผ๋กœ ํƒ์ƒ‰์„ ์ค‘๋‹จํ•œ๋‹ค.

# ๋„ด๋ชจ๋„ด๋ชจ (Easy)

def possible(r, c):
    count = 0
    if r>0 and arr[r-1][c]:
        count += 1
    if c>0 and arr[r][c-1]:
        count += 1
    if r>0 and c>0 and arr[r-1][c-1]:
        count += 1
    return count != 3

def nemo(i):
    global nemo, result
    if i == n*m:
        result += 1
        return 
    
    r, c = divmod(i, m)
    if possible(r, c):
        arr[r][c] = 1
        nemo(i+1)
        arr[r][c] = 0
    nemo(i+1)

n, m = map(int, input().split())
arr = [[0]*m for _ in range(n)]

result = 0
nemo(0)
print(result)
profile
์•„๋ฌด๋ง์ด๋‚˜ํ•˜๊ธฐ

0๊ฐœ์˜ ๋Œ“๊ธ€