티스토리 뷰

 

 

 

 

 

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
import java.util.Scanner;
 
class Main {
    static int[][] frame = new int[5][5];
    static int[] dx = {-1100};
    static int[] dy = {00-11};
    static HashSet<String> hashSet = new HashSet<>();
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        //값 ㅐ우기
        for(int i=0; i<5; i++) {
            for(int j=0; j<5; j++) {
                frame[i][j] = sc.nextInt();
            }
        }
        //출발 지점을 다양하게 하기
        for(int i=0; i<5; i++) {
            for(int j=0; j<5; j++)
                dfs(i, j, 1"");
        }
        System.out.println(hashSet.size());
        
    }
    //범위에서 벗어났는지 확인
    public static boolean isRange(int x, int y) {
        if(x >= 0 && x < 5 && y >= 0 && y < 5)
            return true;
        return false;
    }
    
    public static void dfs(int x, int y, int dept, String number) {
        //7개 이상의 숫자가 되었을     
        if(dept >= 7) {
            if(!hashSet.contains(number))
                hashSet.add(number);
            return;
        }
        for(int i=0; i<4; i++) {
            if(dept>=7) {
                if(!hashSet.contains(number))
                    hashSet.add(number);
                return;
            }
            
            int ix = x + dx[i];
            int iy = y + dy[i];
            
            if(isRange(ix, iy)) {
                String newWord = number + String.valueOf(frame[ix][iy]);
                dfs(ix, iy, dept+1, newWord);
            }
        }
        
        
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함