zoukankan      html  css  js  c++  java
  • 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
    #include <iostream>
    #include<string>
    #include<string.h>
    using namespace std;
    int a[6][6];




    void dfs(int x,int k,string s)
    {int y;
    s+=char(x+'0');
    if(k==8)
    {cout<<s<<endl;return;}
    for(y=1;y<=5;y++)
    {if(a[x][y])
    {a[x][y]=a[y][x]=0;
    dfs(y,k+1,s);
    a[x][y]=a[y][x]=1;
    }
    }
    return ;
    }
    int main()
    {memset(a,0,sizeof(a));
    int i,j;
    for(i=1;i<=5;i++)
    for(j=i+1;j<=5;j++)
    {a[i][j]=1;a[j][i]=1;}
    a[4][1]=a[1][4]=0;
    a[4][2]=a[2][4]=0;
    dfs(1,0,"");
    return 0;
    }

  • 相关阅读:
    JS定时执行,循环执行
    Ecshop(二次开发)
    百度歌曲接口
    给大家讲讲在哪些地方发外链最好
    360浏览器默认以兼容模式或急速模式方式打开页面
    子iframe 怎么调用 父级的JS函数
    ASP 发送邮件
    PHP发送邮件
    php表单数据验证类
    js获取url传递参数
  • 原文地址:https://www.cnblogs.com/lengxia/p/4387805.html
Copyright © 2011-2022 走看看