粗浅学习的DFS,然后试了试,但是只有50分,唔,求调。
下面是代码:
#include <bits/stdc++.h>
using namespace std;
int n;
const int N=11;
bool st[N];
char arr[N];
void DFS (int x)
{
while(x>n)
{
for(int i=1;i<=n;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
return ;
}
for(int i=1;i<=n;i++)
{
if(!st[i])
{
st[i]=true;
arr[x]='Y';
DFS(x+1);
arr[x]='N';
DFS(x+1);
st[i]=false;
arr[x]=0;
}
}
}
int main ()
{
cin>>n;
DFS (1);
return 0;
}
感谢