BOJ - 1890 - 점프

Updated:

import sys

def solution():
    dx = [0, 1]
    dy = [1, 0]

    N = int(input())
    maps = []
    for _ in range(N):
        maps.append(list(map(int, sys.stdin.readline().split())))

    dp = [[0 for _ in range(N)] for _ in range(N)]
    dp[0][0] = 1
    for i in range(N):
        for j in range(N):
            if i == N-1 and j == N-1: continue
            
            mul = maps[i][j]

            for k in range(2):
                nx = i + dx[k] * mul
                ny = j + dy[k] * mul
                if nx < N and ny < N:
                    dp[nx][ny] += dp[i][j]

    print(dp[-1][-1])

solution()

https://www.acmicpc.net/problem/1890

Categories:

Updated:

Leave a comment