IOIjia @ 2023-04-07 17:05:39
#include<bits/stdc++.h>
using namespace std;
int ansx[14],ansy[14],n;
bool t[14][14];
int keyx = 1, keyy = 1;
int fx[2] = {-1,1};
void dfs(int x,int y)
{
if(y == n && !t[x][y])
{
cout << 1;
ansx[keyx] = x;
ansy[keyy] = y;
keyx++;
keyy++;
return;
}
if(!t[x][y])
{
cout << 1;
t[x][y] = true;
for(int i = y; i <= n; i++) t[x][i] = true;
int key = x;
for(int i = y; i <= n && x >= 0; i++)
{
x += fx[0];
t[x][i] = true;
}
x = key;
for(int i = y; i <= n && x <= n; i++)
{
x += fx[1];
t[x][i] = true;
}
}
if(x == n && y < n) dfs(1,y+1);
else dfs(x+1,y);
return;
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
dfs(i,1);
for(int k = 1; k <= 13; k++)
for(int j = 1; j <= 13; j++)
t[k][j] = false;
}
for(int i = 1; i <= keyx; i++) cout << ansx[i] << " ";
cout << endl;
for(int i = 1; i <= keyy; i++) cout << ansy[i] << " ";
return 0;
}
by congege @ 2023-04-20 18:42:10
你这个函数的倒数第三行是不是 dfs(x,y+1)写成dfs(1,y+1)了