-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNo1890.java
More file actions
65 lines (49 loc) · 1.59 KB
/
No1890.java
File metadata and controls
65 lines (49 loc) · 1.59 KB
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
// 백준 1890번.점프
class No1890 {
static int N;
static int[][] map;
static long[][] dp;
static int[] dx = {0,1};
static int[] dy = {1,0};
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
map = new int[N][N];
dp = new long[N][N];
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());
}
Arrays.fill(dp[i], -1);
}
System.out.println(solve(0,0));
}
static long solve(int x, int y) {
if(dp[x][y] != -1)
return dp[x][y];
if(x == N-1 && y == N-1) {
return 1;
}
if(map[x][y] == 0)
return 0;
dp[x][y] = 0;
for (int i = 0; i < 2; i++) {
int nx = x + dx[i]*map[x][y];
int ny = y + dy[i]*map[x][y];
if(!isRange(nx, ny))
continue;
dp[x][y] += solve(nx,ny);
}
return dp[x][y];
}
static boolean isRange(int x , int y) {
if( x < 0 || x >= N || y < 0 || y >= N) return false;
return true;
}
}