Uva291 the house of Santa Claus DFS

Source: Internet
Author: User

Output all Euler's path in a graph... Simply use DFS. The graph is fixed.

The House of Santa Claus
Time limit:3000 Ms   Memory limit:Unknown   64bit Io format:% LLD & % LlU

[Submit] [go
Back] [Status]

Description


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

# Include <iostream> # include <cstring> # include <string> # include <cstdio> # include <cmath> # include <algorithm> using namespace STD; int map [10] [10]; int stack [200]; void DFS (int x, int CNT, int top) {stack [top ++] = X; if (CNT = 8) {for (INT I = 0; I <top; I ++) printf ("% d", stack [I]); printf ("\ n"); return;} For (INT I = 1; I <= 5; I ++) {If (Map [x] [I]) {map [x] [I] = map [I] [x] = 0; DFS (I, CNT + 1, top ); map [x] [I] = map [I] [x] = 1 ;}} void ini T () {memset (MAP, 0, sizeof (MAP); For (INT I = 1; I <= 5; I ++) for (Int J = 1; j <= 5; j ++) if (I! = J) map [I] [J] = 1; Map [1] [4] = map [4] [1] = 0; map [2] [4] = map [4] [2] = 0;} int main () {Init (); DFS (1, 0, 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.