練習問題:迷路を歩く(java遡及dfs)


package lanqiaobei;

import java.util.Scanner;

/*
  :   
   n m  2    ,'S'       ,'T'       ,'#'        ,'.'         。    'S'    'T',          ,           ,         。                   。
    
     n,m (1≤n,m≤10)      。
     n        。
    
          。
    1
2 3
S.#
..T
    1
2
    2
3 3
S..
.#.
..T
    2
2
 */
public class ZouMiGong {
    private int cont=0;
    private void move(char[][] mg,int x,int y){
        if(mg[x][y]=='T'){
            cont++;
        }else {
            if (x0&&mg[x-1][y]!='#'){
               mg[x][y]='#';
               move(mg,x-1,y);
               mg[x][y]='.';
           }
            if (y<=mg[0].length-1&&y>0&&mg[x][y-1]!='#'){
                mg[x][y]='#';
                move(mg,x,y-1);
                mg[x][y]='.';
            }
        }
    }

    public static void main(String[] args) {
        ZouMiGong g=new ZouMiGong();
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        int y=sc.nextInt();
        int startx=0;
        int starty=0;
        char[][] a=new char[x][y];
        for (int i = 0; i