-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path241213-1189.java
52 lines (48 loc) · 1.47 KB
/
241213-1189.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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int R;
static int C;
static int K;
static char[][] map;
static int answer = 0;
static int[] dr = { -1, 1, 0, 0 };
static int[] dc = { 0, 0, -1, 1 };
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
R = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
map = new char[R][C];
for (int i = 0; i < R; i++) {
String row = br.readLine();
map[i] = row.toCharArray();
}
dfs(R - 1, 0, 1);
System.out.print(answer);
}
static void dfs(int r, int c, int depth) {
if (depth == K) {
if (r == 0 && c == C - 1) {
answer++;
}
return;
}
if (r == 0 && c == C - 1) {
return;
}
map[r][c] = 'v';
for (int i = 0; i < 4; i++) {
int nr = r + dr[i];
int nc = c + dc[i];
if (nr < 0 || nr >= R || nc < 0 || nc >= C || map[nr][nc] == 'T' || map[nr][nc] == 'v') {
continue;
}
dfs(nr, nc, depth + 1);
}
map[r][c] = '.';
}
}