728x90
import java.util.Scanner;
import java.util.HashSet;
public class Main {
static int[] dx = {-1,1,0,0};
static int[] dy = {0,0,-1,1};
static int[][] arr;
static HashSet<String> list;
static int N;
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
N = 5;
list = new HashSet<String>();
arr = new int[N][N];
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
arr[i][j] = scan.nextInt();
}
}
String s = new String();
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
DFS(i,j,0,s);
}
}
System.out.println(list.size());
scan.close();
}
public static void DFS(int x, int y, int depth, String s) {
// 길이가 6일때 set에 넣고 종료한다.
if(depth == 6) {
list.add(s);
return;
}
// 상하좌우 이동할 수 있다. 왔던 길도 다시 올 수 있다.
for(int i = 0; i < 4; i++) {
int nextX = dx[i] + x;
int nextY = dy[i] + y;
if(nextX < 0 || nextY < 0 || nextX >= N || nextY >= N)
continue;
DFS(nextX, nextY, depth + 1, s + arr[x][y]);
}
}
}
728x90
'CS > Algorithm' 카테고리의 다른 글
[백준:2583] 영역구하기 - JAVA (0) | 2021.04.11 |
---|---|
HashSet - java (0) | 2021.04.11 |
[백준 : 4889] 안정적인 문자열 - JAVA (0) | 2021.04.05 |
[백준:3986번] 좋은 단어 - JAVA (0) | 2021.04.04 |
[백준:1935] 후위 표기식2 - JAVA (0) | 2021.04.04 |