291-the House of Santa Claus

Source: Internet
Author: User
Source: http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & category = 4 & problem = 227 & mosmsg = Submission + received + with + ID + 14026069

The House of Santa Claus
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 penpencil 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 requireAllThe possibilities when starting in the lower left corner. Follow the example in Figure 2 while defining your stretch.


Figure:This sequence wocould give the outputline 153125432

All the possibilities have to be listed in the outputfile by increasing order, meaning that1234...Is listed before1235....

Output

So, an outputfile cocould look like this:

1243512313245123...15123421

 
Question: one stroke. Draw from 1 and output all possible situations
Problem: DFS only needs to use an array path to save the path ~~
 
AC code:
#include<iostream>using namespace std;bool edge[6][6]={0},visit[6][6];int path[10];void dfs(int pos,int step){if(step==8){for(int i=0;i<9;i++)cout<<path[i];cout<<endl;return ;}for(int i=1;i<6;i++){if(edge[pos][i]&&visit[pos][i]){visit[pos][i]=false;visit[i][pos]=false;path[step+1]=i;dfs(i,step+1);visit[pos][i]=true;visit[i][pos]=true;}}}int main(){edge[1][2]=true;edge[1][5]=true;edge[1][3]=true;edge[2][1]=true;edge[2][5]=true;edge[2][3]=true;edge[3][2]=true;edge[3][5]=true;edge[3][4]=true;edge[3][1]=true;edge[4][3]=true;edge[4][5]=true;edge[5][3]=true;edge[5][4]=true;edge[5][1]=true;edge[5][2]=true;for(int i=0;i<6;i++)for(int j=0;j<6;j++)visit[i][j]=edge[i][j];path[0]=1;dfs(1,0);return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.