File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.util.* ;
3+ import java.io.* ;
4+
5+ public class Main {
6+ private static final int H = 0 ;
7+ private static final int V = 1 ;
8+ private static final int D = 2 ;
9+
10+ private static int SIZE ;
11+ static int [][] map;
12+ static long [][][] dp;
13+
14+ public static void main (String [] args ) throws Exception {
15+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
16+ SIZE = Integer . parseInt(br. readLine());
17+
18+ map = new int [SIZE + 1 ][SIZE + 1 ];
19+ dp = new long [3 ][SIZE + 1 ][SIZE + 1 ];
20+
21+ StringTokenizer st;
22+ for (int i = 1 ; i <= SIZE ; i++ ) {
23+ st = new StringTokenizer (br. readLine());
24+ for (int j = 1 ; j <= SIZE ; j++ ) {
25+ if (1 == Integer . parseInt(st. nextToken())) {
26+ map[i][j] = 1 ;
27+ }
28+ }
29+ }
30+
31+ dp[H ][1 ][2 ] = 1 ;
32+
33+ for (int i = 1 ; i <= SIZE ; i++ ) {
34+ for (int j = 1 ; j <= SIZE ; j++ ) {
35+ if (i == 1 && j <= 2 ) continue ;
36+
37+ if (map[i][j] == 1 ) continue ;
38+ dp[H ][i][j] = dp[H ][i][j- 1 ] + dp[D ][i][j- 1 ];
39+ dp[V ][i][j] = dp[V ][i- 1 ][j] + dp[D ][i- 1 ][j];
40+
41+ if (map[i][j- 1 ] == 1 || map[i- 1 ][j] == 1 ) continue ;
42+ dp[D ][i][j] = dp[H ][i- 1 ][j- 1 ] + dp[V ][i- 1 ][j- 1 ] + dp[D ][i- 1 ][j- 1 ];
43+ }
44+ }
45+
46+ System . out. println(dp[H ][SIZE ][SIZE ] + dp[V ][SIZE ][SIZE ] + dp[D ][SIZE ][SIZE ]);
47+ }
48+ }
49+ ```
You can’t perform that action at this time.
0 commit comments