문제
코드
import sys
input = sys.stdin.readline
def solve(n: int, graph: list) -> int:
d = [[[0] * 3 for _ in range(n)] for _ in range(n)]
d[0][1][0] = 1
for i in range(1, n):
if graph[0][i] == 1:
break
else:
d[0][i][0] = 1
for i in range(1, n):
for j in range(2, n):
if not graph[i][j]:
d[i][j][0] = d[i][j-1][0] + d[i][j-1][2]
if not graph[i][j]:
d[i][j][1] = d[i-1][j][1] + d[i-1][j][2]
if not graph[i][j-1] and not graph[i-1][j] and not graph[i][j]:
d[i][j][2] = d[i-1][j-1][1] + d[i-1][j-1][0] + d[i-1][j-1][2]
return sum(d[-1][-1])
if __name__ == '__main__':
n = int(input())
graph = [list(map(int, input().split())) for _ in range(n)]
print(solve(n, graph))
결과
출처 & 깃허브
boj 17069
github