UVA291 The House Of Santa Claus DFS

來源:互聯網
上載者:User

輸出一張圖上的所有歐拉路。。。直接DFS就可以了。圖是固定的。

The House Of Santa Claus
Time Limit: 3000MS   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 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:

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 init(){    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);}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.