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
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 );}