当前位置:网站首页>Two dimensional DFS

Two dimensional DFS

2022-06-26 14:23:00 Honestbutter-

link

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
const int N=20;
int g[N][N],n;
bool st[N];
LL ans;
void dfs(int u,LL x)	//x Record answer 
{
    
	if(u==n)
	{
    
		ans=max(ans,x);
		return;
	}
	
	int l=0;	// First fix the first element 
	for(int i=1;i<=2*n-1;i++)
	if(!st[i])
	{
    
		l=i;			
		break;
	}
	
	st[l]=true;
	
	for(int i=l+1;i<=2*n;i++)
	if(!st[i])	// Fix the second element again 
	{
    
		st[i]=true;
		dfs(u+1,x^g[l][i]);	// Keep searching u+1
		st[i]=false;
	}
	
	st[l]=false;	

}
int main()
{
    
	cin>>n;
	for(int i=1;i<=2*n-1;i++)
		for(int j=i+1;j<=2*n;j++)
		cin>>g[i][j];
	
	dfs(0,0);
	
	cout<<ans<<endl;
	
	return 0;
}
原网站

版权声明
本文为[Honestbutter-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170508103631.html