题目
代码
#include <bits/stdc++.h>
using namespace std;
int g[5][5];
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
int ans;
void dfs(int x, int y, int t)
{
g[x][y] = t;
if (t >= 16)
{
ans++;
g[x][y] = 0;
return;
}
for (int i = 0; i < 4; i++)
{
int nx = x + dx[i], ny = y + dy[i];
if (nx < 1 || ny < 1 || nx > 4 || ny > 4)
continue;
if (g[nx][ny])
continue;
dfs(nx, ny, t + 1);
}
g[x][y] = 0;
}
int main()
{
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= 4; j++)
dfs(i, j, 1);
}
cout << ans;
return 0;
}