반응형
코드
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int arr[8][8], ch[8][8];
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int cnt = 0;
void DFS(int x, int y)
{
int i, xx, yy;
if (x == 7 && y == 7)
{
++cnt;
}
else
{
for (i = 0; i < 4; ++i)
{
xx = x + dx[i];
yy = y + dy[i];
if(xx < 1 || xx > 7 || yy < 1 || yy > 7) continue;
if (arr[xx][yy] == 0 && ch[xx][yy] == 0)
{
ch[xx][yy] = 1;
DFS(xx, yy);
ch[xx][yy] = 0;
}
}
}
}
int main(void)
{
int i, j;
for (i = 1; i <= 7; ++i)
{
for (j = 1; j <= 7; ++j)
{
cin >> arr[i][j];
}
}
ch[1][1] = 1;
DFS(1, 1);
cout << cnt << endl;
return 0;
}
출력 결과
채점 결과
해당 포스트는 'it 취업을 위한 알고리즘 문제풀이 (with C/C++) : 코딩테스트 대비' 강의를 수강하며 개인 백업용으로 메모하였습니다.
인프런: https://www.inflearn.com/course/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98#
반응형