-
Notifications
You must be signed in to change notification settings - Fork 0
/
17070.java
87 lines (75 loc) · 1.8 KB
/
17070.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.io.*;
public class Main {
static int N, ans;
static int map[][];
static int dx[] = {0,1,1}; // 우측 / 대각선/ 하단
static int dy[] = {1,1,0};
public static void main(String[] args) throws Exception{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(input.readLine());
map = new int[N][N];
for(int i=0; i<N; i++) {
String row[] = input.readLine().split(" ");
for(int j=0; j<N; j++) {
map[i][j] = Integer.parseInt(row[j]);
}
}
move(0,1,0);
System.out.println(ans);
}
private static void move(int x, int y, int flag) {
if(x == N-1 && y == N-1) {
ans++;
return;
}
// 0 : 우측 , 1: 대각선, 2: 하단
if(flag == 0) {
for(int i=0; i<2; i++) {
int nx = x+dx[i];
int ny = y+dy[i];
if(rightRange(nx, ny)) {
if(i==1) { // 대각선이면 추가 칸 검사
if(map[x][y+1] == 0 && map[x+1][y] == 0) {
move(nx, ny, 1);
}
}else {
move(nx, ny, 0);
}
}
}
}else if(flag == 1) {
for(int i=0; i<3; i++) {
int nx = x+dx[i];
int ny = y+dy[i];
if(rightRange(nx, ny)) {
if(i==1) { // 대각선이면 추가 칸 검사
if(map[x][y+1] == 0 && map[x+1][y] == 0) {
move(nx, ny, 1);
}
}else if(i == 0){
move(nx, ny, 0);
}else {
move(nx, ny, 2);
}
}
}
}else {
for(int i=1; i<3; i++) {
int nx = x+dx[i];
int ny = y+dy[i];
if(rightRange(nx, ny)) {
if(i==1) { // 대각선이면 추가 칸 검사
if(map[x][y+1] == 0 && map[x+1][y] == 0) {
move(nx, ny, 1);
}
}else {
move(nx, ny, 2);
}
}
}
}
}
private static boolean rightRange(int x, int y) {
return x>-1 && y>-1 && x<N && y<N && map[x][y] == 0? true : false;
}
}