DevYoon

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋“ฑ๊ตฃ๊ธธ (Python) ๋ณธ๋ฌธ

PS/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋“ฑ๊ตฃ๊ธธ (Python)

gimewn 2022. 4. 26. 15:58

link ๐Ÿ”— https://programmers.co.kr/learn/courses/30/lessons/42898

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋“ฑ๊ตฃ๊ธธ

๊ณ„์†๋˜๋Š” ํญ์šฐ๋กœ ์ผ๋ถ€ ์ง€์—ญ์ด ๋ฌผ์— ์ž ๊ฒผ์Šต๋‹ˆ๋‹ค. ๋ฌผ์— ์ž ๊ธฐ์ง€ ์•Š์€ ์ง€์—ญ์„ ํ†ตํ•ด ํ•™๊ต๋ฅผ ๊ฐ€๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ง‘์—์„œ ํ•™๊ต๊นŒ์ง€ ๊ฐ€๋Š” ๊ธธ์€ m x n ํฌ๊ธฐ์˜ ๊ฒฉ์ž๋ชจ์–‘์œผ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ๊ทธ๋ฆผ์€ m =

programmers.co.kr

 

def solution(m, n, puddles):
    board = [[0]*(m+1) for _ in range(n+1)]
    puddles = [[j, i] for [i, j] in puddles]
    board[1][1] = 1
    for y in range(1, n+1):
        for x in range(1, m+1):
            if y == 1 and x == 1:continue
            if [y, x] in puddles:
                board[y][x] = 0
            else:
                board[y][x] = (board[y-1][x]+board[y][x-1])%1000000007
    return board[n][m]