The House Of Santa Claus(dfs)
来源:互联网 发布:python form import 编辑:程序博客网 时间:2024/04/27 15:25
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<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;
}
- The House Of Santa Claus(dfs)
- UVA 291 The House Of Santa Claus(DFS算法)
- UVA 291 The House Of Santa Claus(DFS/深搜)
- The House Of Santa Claus
- The House Of Santa Claus
- uva 291 The house of santa claus DFS
- UVA291_The House Of Santa Claus(DFS)
- (深度搜索)The House Of Santa Claus
- UVa 291 - The House Of Santa Claus
- uva 291The House Of Santa Claus
- 291 - The House Of Santa Claus
- (DFS11.2.1)UVA 291 The House Of Santa Claus(使用DFS来解决一笔画问题)
- UVA 291 The House Of Santa Claus 图的遍历
- Santa Claus
- Codeforces748D-Santa Claus and a Palindrome(贪心,构造)
- Santa claus would not come~
- Codeforces753A Santa Claus and Candies
- codeforces748c-Santa Claus and Robot
- C++四种强制类型转换运算符
- 百度定位
- dom.style.height, offsetWidth, scrollWidth, clientWidth区别
- hdu 4920 Matrix multiplication(矩阵相乘)2014多校训练第5场
- HDU 1686 Oulipo (KMP)
- The House Of Santa Claus(dfs)
- Linux中tar的用法总结
- hdu 1106 排序 20140805.cpp
- 计算CRC16
- TCP与UDP在socket编程中的区别
- [Linux]Makefile入门
- Transfer Learning 资料
- 2014 Multi-University Training Contest 5 HDOJ 4920 Matrix multiplication
- UVA 12186 - Another Crisis(树形DP)