The House Of Santa Claus
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
In your childhood you most likely had to solve the riddle of the house of Santa Claus. Do you remember that the importance was on drawing the house in a stretch without lifting the pencil and not drawing a line twice? As a reminder it has to look like shown in Figure 1.
Figure: The House of Santa Claus
Well, a couple of years later, like now, you have to ``draw'' the house again but on the computer. As one possibility is not enough, we require all the possibilities when starting in the lower left corner. Follow the example in Figure 2 while defining your stretch.
Figure: This Sequence would give the Outputline 153125432
All the possibilities have to be listed in the outputfile by increasing order, meaning that 1234... is listed before 1235... .
Output
So, an outputfile could look like this:
12435123 13245123 ... 15123421
一道非常简单的深搜题:
#include <iostream>
#include <string.h>
using namespace std;
int map[6][6];
int s[10];
void set_map()
{
int i,j;
for(i=0;i<6;i++)
for(j=0;j<6;j++)
map[i][j]=1;
map[1][4]=map[4][1]=0;
map[2][4]=map[4][2]=0;
}
void print()
{
int i;
for(i=0;i<9;i++)
cout<<s[i];
cout<<endl;
}
void dfs(int x,int k)
{
int i;
s[k]=x;
if(k==8)
{
print();
return ;
}
for(i=1;i<6;i++)
if(x!=i&&map[x][i])
{
map[x][i]=map[i][x]=0;
dfs(i,k+1);
map[x][i]=map[i][x]=1;
}
}
int main()
{
set_map();
dfs(1,0);
return 0;
}