dfs

#include <bits/stdc++.h>
using namespace std;
bool a1[2][2]={false};
int d[4][2]={{0,-1},{0,1},{1,0},{-1,0}}; 
vector<pair<int,int>> path;
void dfs(int x,int y)
{
	if(x==2&&y==2)
	{
		for(auto a:path)
		{
			cout<<"("<<a.first<<","<<a.second<<")";
		}
		cout<<endl;
		return ; 
	}
	for(auto a2:d)
	{
		int nx=x+a2[0],ny=y+a2[1];
		if(a1[nx][ny]==false&&nx<=2&&nx>=0&&ny<=2&&ny>=0)
		{
			a1[nx][ny]=true;
			path.push_back({nx,ny});
			dfs(nx,ny);
			path.pop_back();
			a1[nx][ny]=false;
		}
	}
}
int main()
{
	dfs(0,0);
	return 0;
}

  

posted @ 2025-04-19 10:00  hanxuyao  阅读(16)  评论(0)    收藏  举报