搜索,什么是搜索啊大佬们
  • 板块灌水区
  • 楼主cxsxlg
  • 当前回复7
  • 已保存回复7
  • 发布时间2021/11/27 21:42
  • 上次更新2023/11/3 23:25:10
查看原帖
搜索,什么是搜索啊大佬们
538258
cxsxlg楼主2021/11/27 21:42
#include<bits/stdc++.h>
using namespace std;
char x[50][50];
int bu[50][50], d;
bool nf(int h,int l)
{
	for(int i=1;i<h;i++)
	{
		for(int o=1;o<=8;o++)
		{
			if(bu[i][o]==1)
			{
				if(l==o||h-i==l-o||i+o==h+l) return false;
			}
		}
	}
	return true;
}
void dfs(int h)
{
	//cout<<h<<" ";
	if(h==9)
	{
		d++;
		cout<<"No. "<<d<<endl;
		for(int i=1;i<=8;i++)
		{
			for(int o=1;o<=8;o++)
			{
				cout<<bu[o][i]<<" ";
			}
			cout<<endl;
		}
		return;
	}
	for(int i=1;i<=8;i++)
	{
		if(nf(h,i))
		{
			bu[h][i]=1;
			dfs(h+1);
			bu[h][i]=0;
		}
	}
}
int main()
{
	dfs(1);
	return 0;
}

其实它的整体我都知道,但40-43行我就看不懂了,为什么它变来变去啊这,它这个不会对后面有影响吗

emmm,这不是洛谷的,是[1700:八皇后问题],noi的(http://noi.openjudge.cn/ch0205/1700/) 请大家帮我解答一下,谢谢!

2021/11/27 21:42
加载中...