|
| 1 | +import java.util.*; |
| 2 | +import java.io.*; |
| 3 | + |
| 4 | +public class Main { |
| 5 | + private static int R; |
| 6 | + private static int C; |
| 7 | + private static int K; |
| 8 | + private static Character[][] arr; |
| 9 | + private static boolean[][] visit; |
| 10 | + |
| 11 | + private static int[] dx = {0, 0, -1, 1}; |
| 12 | + private static int[] dy = {1, -1, 0, 0}; |
| 13 | + private static int count = 0; |
| 14 | + |
| 15 | + private static class Node { |
| 16 | + int x; |
| 17 | + int y; |
| 18 | + int t; |
| 19 | + |
| 20 | + public Node(int x, int y, int t) { |
| 21 | + this.x = x; |
| 22 | + this.y = y; |
| 23 | + this.t = t; |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + private static Queue<Node> queue = new LinkedList<>(); |
| 28 | + |
| 29 | + public static void main(String[] args) throws IOException { |
| 30 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 31 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 32 | + |
| 33 | + R = Integer.parseInt(st.nextToken()); |
| 34 | + C = Integer.parseInt(st.nextToken()); |
| 35 | + K = Integer.parseInt(st.nextToken()); |
| 36 | + |
| 37 | + arr = new Character[R][C]; |
| 38 | + visit = new boolean[R][C]; |
| 39 | + |
| 40 | + for (int i = 0; i < R; i++) { |
| 41 | + String temp = br.readLine(); |
| 42 | + for (int j = 0; j < C; j++) { |
| 43 | + arr[i][j] = temp.charAt(j); |
| 44 | + } |
| 45 | + } |
| 46 | + visit[R - 1][0] = true; |
| 47 | + dfs(R - 1, 0, 1); |
| 48 | + System.out.print(count); |
| 49 | + } |
| 50 | + |
| 51 | + private static void dfs(int x, int y, int depth) { |
| 52 | + if (x == 0 && y == C - 1) { |
| 53 | + if (depth == K) count++; |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + for (int i = 0; i < 4; i++) { |
| 58 | + int nx = x + dx[i]; |
| 59 | + int ny = y + dy[i]; |
| 60 | + |
| 61 | + if (nx >= 0 && nx < R && ny >= 0 && ny < C && |
| 62 | + !visit[nx][ny] && arr[nx][ny] != 'T') { |
| 63 | + |
| 64 | + visit[nx][ny] = true; |
| 65 | + dfs(nx, ny, depth + 1); |
| 66 | + visit[nx][ny] = false; |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments