#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <math.h>
using namespace std;
int map[7][7], cnt = 0;
bool check[7][7];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void DFS(int row, int col){
if(row==6 && col==6){
cnt++;
printf("----answer-----\n");
for(int i=0; i<7; i++){
for(int j=0; j<7; j++){
printf("%d ", check[i][j]);
}
printf("\n");
}
printf("---------\n");
}
for(int i=0; i<4; i++){
int nx = row+dx[i];
int ny = col+dy[i];
if(nx<0 || nx>6) continue;
if(ny<0 || ny>6) continue;
if(map[nx][ny] == 1 || check[nx][ny]) continue;
check[nx][ny] = 1;
DFS(nx,ny);
check[nx][ny] = 0;
}
}
int main() {
//freopen("input.txt.txt","rt",stdin);
for(int i=0; i<7; i++){
for(int j=0; j<7; j++){
scanf("%d", &map[i][j]);
}
}
check[0][0] = 1;
DFS(0, 0);
printf("%d",cnt);
}
결과
(미로)
0 0 0 0 0 0 0
0 1 1 1 1 1 0
0 0 0 1 0 0 0
1 1 0 1 0 1 1
1 1 0 0 0 0 1
1 1 0 1 1 0 0
1 0 0 0 0 0 0
----answer-----
1 0 0 0 0 0 0
1 0 0 0 0 0 0
1 1 1 0 0 0 0
0 0 1 0 0 0 0
0 0 1 0 0 0 0
0 0 1 0 0 0 0
0 0 1 1 1 1 1
---------
----answer-----
1 0 0 0 0 0 0
1 0 0 0 0 0 0
1 1 1 0 0 0 0
0 0 1 0 0 0 0
0 0 1 0 0 0 0
0 0 1 0 0 1 1
0 0 1 1 1 1 1
---------
----answer-----
1 0 0 0 0 0 0
1 0 0 0 0 0 0
1 1 1 0 0 0 0
0 0 1 0 0 0 0
0 0 1 1 1 1 0
0 0 0 0 0 1 0
0 0 0 0 0 1 1
---------
----answer-----
1 0 0 0 0 0 0
1 0 0 0 0 0 0
1 1 1 0 0 0 0
0 0 1 0 0 0 0
0 0 1 1 1 1 0
0 0 0 0 0 1 1
0 0 0 0 0 0 1
---------
----answer-----
1 1 1 1 1 1 1
0 0 0 0 0 0 1
0 0 0 0 1 1 1
0 0 0 0 1 0 0
0 0 0 0 1 1 0
0 0 0 0 0 1 0
0 0 0 0 0 1 1
---------
----answer-----
1 1 1 1 1 1 1
0 0 0 0 0 0 1
0 0 0 0 1 1 1
0 0 0 0 1 0 0
0 0 0 0 1 1 0
0 0 0 0 0 1 1
0 0 0 0 0 0 1
---------
----answer-----
1 1 1 1 1 1 1
0 0 0 0 0 0 1
0 0 0 0 1 1 1
0 0 0 0 1 0 0
0 0 1 1 1 0 0
0 0 1 0 0 0 0
0 0 1 1 1 1 1
---------
----answer-----
1 1 1 1 1 1 1
0 0 0 0 0 0 1
0 0 0 0 1 1 1
0 0 0 0 1 0 0
0 0 1 1 1 0 0
0 0 1 0 0 1 1
0 0 1 1 1 1 1
---------
8
'Algorithm > etc' 카테고리의 다른 글
[그래프] 인접 리스트(adjency list) 코드 구현 C++ (0) | 2022.01.15 |
---|---|
DFS 최소 비용 (DFS 매개변수 이용) (0) | 2022.01.15 |
그래프 탐색 DFS (0) | 2022.01.15 |
DFS 부분집합 찾기 (0) | 2022.01.14 |
이진트리 깊이우선탐색(DFS) (0) | 2022.01.14 |