UVA291_The House Of Santa Claus(DFS)

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.

 figure20 
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.

 figure33 
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
解题报告

计算从节点1出发的所有可能访问序列,要求按节点递增序列输出

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
int mmap[6][6];
int vis[6][6];
void dfs(int x,int cnt,string str)
{
    str+=char(x+'0');
    if(cnt==8)
    {
            cout<<str;
        cout<<endl;
        return;
    }
    for(int i=1;i<=5;i++)
    {
        if(mmap[x][i]&&!vis[x][i])
        {
            vis[x][i]=vis[i][x]=1;
            dfs(i,cnt+1,str);
            vis[x][i]=vis[i][x]=0;
        }
    }
}
int main()
{
    for(int i=1;i<=5;i++)
    {
        for(int j=1;j<=5;j++)
            mmap[i][j]=1;
        mmap[i][i]=0;
    }
    mmap[1][4]=mmap[4][1]=mmap[2][4]=mmap[4][2]=0;
    dfs(1,0,"");
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值