#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
using namespace std;
#define INF (1<<29)
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define PB push_back
#define FOR(i,n) for(int i = 0;i<n;i++)
#define PI acos(-1.0)
#define EPS 1e-9
#define MP(a,b) make_pair(a,b)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define LL long long
#define MX 100000
#define MOD 1000000007
int edge[10][10],u1[]={2,3,5},u2[]={1,3,5},u3[]={1,2,4,5},u4[]={3,5},u5[]={1,2,3,4};
void drawing(int stk, int n)
{
int i;
if(n==8)
{
cout<<stk<<endl;
return;
}
int prev=stk%10;
if(prev==1)
{
for(i=0;i<3;i++)
if(!edge[prev][u1[i]])
{
edge[prev][u1[i]]=1;
edge[u1[i]][prev]=1;
drawing(stk*10+u1[i], n+1);
edge[prev][u1[i]]=0;
edge[u1[i]][prev]=0;
}
}
else if(prev==2)
{
for(i=0;i<3;i++)
if(!edge[prev][u2[i]])
{
edge[prev][u2[i]]=1;
edge[u2[i]][prev]=1;
drawing(stk*10+u2[i], n+1);
edge[prev][u2[i]]=0;
edge[u2[i]][prev]=0;
}
}
else if(prev==3)
{
for(i=0;i<4;i++)
if(!edge[prev][u3[i]])
{
edge[prev][u3[i]]=1;
edge[u3[i]][prev]=1;
drawing(stk*10+u3[i], n+1);
edge[prev][u3[i]]=0;
edge[u3[i]][prev]=0;
}
}
else if(prev==4)
{
for(i=0;i<2;i++)
if(!edge[prev][u4[i]])
{
edge[prev][u4[i]]=1;
edge[u4[i]][prev]=1;
drawing(stk*10+u4[i], n+1);
edge[prev][u4[i]]=0;
edge[u4[i]][prev]=0;
}
}
else if(prev==5)
{
for(i=0;i<4;i++)
if(!edge[prev][u5[i]])
{
edge[prev][u5[i]]=1;
edge[u5[i]][prev]=1;
drawing(stk*10+u5[i], n+1);
edge[prev][u5[i]]=0;
edge[u5[i]][prev]=0;
}
}
}
int main()
{
drawing(1,0);
return 0;
}
No comments:
Post a Comment