forked from SSAFY-5959-STUDY/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOJ1890.java
54 lines (40 loc) · 1.21 KB
/
BOJ1890.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
package cocodingding;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ1890 {
static int n;
static int[][] turn, map;
static long[][] result;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
turn = new int[][] { { 0, 1 }, { 1, 0 } };
map = new int[n][n];
result=new long[n][n];//크기떄문에 result를 long으로 둔다
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 0; j < n; j++) {
map[i][j] = Integer.parseInt(st.nextToken());
}
}
result[0][0]=1;//처음을 1로 줌
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
int temp=map[i][j];
if(temp==0) break; //마지막 도착지점
for(int k=0;k<2;k++) {
int x=i+turn[k][0]*temp;
int y=j+turn[k][1]*temp;
if(checking(x, y))
result[x][y]+=result[i][j];
}
}
}
System.out.println(result[n-1][n-1]);
}
private static boolean checking(int x, int y) {
return (x >= 0 && y >= 0 && x < n && y < n );
}
}