首页 > 代码库 > HDU 2894 DeBruijin 兹鼓欧拉回路

HDU 2894 DeBruijin 兹鼓欧拉回路

题目来源:HDU 2894 DeBruijin

题意:

思路:


#include <cstdio>
#include <cstring>
using namespace std;
int vis[5000], ans[5000];
int len, n;
void dfs(int u)
{
	int v = ((u<<1)&((1<<n)-1));
	if(!vis[v])
	{
		vis[v] = 1;
		dfs(v);
		ans[len++] = 0;
	}
	if(!vis[v+1])
	{
		vis[v+1] = 1;
		dfs(v+1);
		ans[len++] = 1;
	}
}
int main()
{
	while(scanf("%d", &n) != EOF)
	{
		memset(vis, 0, sizeof(vis));
		len = 0;
		dfs(0);
		printf("%d ", (1<<n));
		for(int i = 1; i < n; i++)
			printf("0");
		for(int i = len-1; i >= n-1; i--)
			printf("%d", ans[i]);
		puts("");
	}
	return 0;
}


HDU 2894 DeBruijin 兹鼓欧拉回路