File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 1+ # https://www.acmicpc.net/problem/11404
2+ import sys
3+ from collections import defaultdict
4+ from collections import deque
5+
6+ N = int (input ())
7+ board = [list (map (int , input ().split ())) for _ in range (N )]
8+ dp = [[[0 for _ in range (N )] for _ in range (N )] for _ in range (3 )]
9+
10+ def solution ():
11+ # 선행조건
12+ dp [0 ][0 ][1 ] = 1
13+ for i in range (2 , N ):
14+ if board [0 ][i ] == 0 :
15+ dp [0 ][0 ][i ] = dp [0 ][0 ][i - 1 ]
16+
17+
18+ for row in range (1 , N ):
19+ for col in range (1 , N ):
20+ # 최종 위치가 대각선인 경우
21+ if board [row ][col ] == 0 and board [row ][col - 1 ] == 0 and board [row - 1 ][col ] == 0 : # 빈자리 조건
22+ dp [1 ][row ][col ] = dp [0 ][row - 1 ][col - 1 ] + dp [1 ][row - 1 ][col - 1 ] + dp [2 ][row - 1 ][col - 1 ]
23+
24+ if board [row ][col ] == 0 : # 현재 위치가 비어있어야 함
25+ dp [0 ][row ][col ] = dp [0 ][row ][col - 1 ] + dp [1 ][row ][col - 1 ] # 우방향 빈자리 조건
26+ dp [2 ][row ][col ] = dp [2 ][row - 1 ][col ] + dp [1 ][row - 1 ][col ] # 아래방향 빈자리 조건
27+
28+
29+ return sum (dp [i ][N - 1 ][N - 1 ] for i in range (3 ))
30+
31+ print (solution ())
You can’t perform that action at this time.
0 commit comments