50分,求调!
查看原帖
50分,求调!
1377492
CodeJuve楼主2025/7/24 15:07

粗浅学习的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;
}

感谢

2025/7/24 15:07
加载中...