UVA 291 The House Of Santa Claus DFS
题目:
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:
12435123
13245123
...
1512342 分析:
用5个点表示圣诞老人的房子,除了1-4和2-4两条边外,所有的边都相连,问能否从左下角(点1)一笔画出房子的路径有哪些,逐个点输出出来。
例如:
12435123
13245123
......
15123421
分析:
从点1开始,深搜遍历所有的边,直到遍历的边的个数达到8时递归结束。
AC code:
#include<bits/stdc++.h>
using namespace std;
int m[][];
void init()
{
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(i!=j) m[i][j]=;
else m[i][j]=;
}
}
m[][]=m[][]=;
m[][]=m[][]=;
}
void dfs(int e,int k,string s)
{
s+=(k+'');
if(e==)
{
cout<<s<<endl;
return;
}
for(int i=;i<=;i++)
{
if(m[k][i])
{
m[i][k]=m[k][i]=;
dfs(e+,i,s);
m[i][k]=m[k][i]=;
}
}
}
int main()
{
init();
dfs(,,"");
}
最新文章
- IM消息送达保证机制实现(二):保证离线消息的可靠投递
- string.empty和null的区别
- CentOS下安装LAMP环境
- 怎么实现ZBrush中Alt键和Shift键的灵活运用
- 基于gitosis的Git云端服务器配置
- js控制input type=checkbox 的勾选
- Delphi 使用之函数
- Java JDK 动态代理使用及实现原理分析
- memwatch
- 自动引用计数(ARC)
- wl18xx编译的时候出现WARNING: ";simple_open"; WARNING: ";wl12xx_get_platform_data";
- 【Python初学】深copy&;浅copy
- Python_正则表达式样例
- WEB前端常见面试题汇总:(一)
- (转)Cesium教程系列汇总
- Spring boot配置logback
- Luogu P2292 [HNOI2004]L语言
- PyJWT 使用
- 模拟curl函数
- 移动端web开发整理
热门文章
- linux服务器上配置进行kaggle比赛的深度学习tensorflow keras环境详细教程
- mysql常用命令杂记
- IDA+Windbg IDA+OD 连动调试插件
- 123: The filename, directory name, or volume label syntax is incorrect今天玩nginx的时候报错
- SpringBoot(14)—注解装配Bean
- Python--方法/技巧在哪用的典型例子
- Python爬取猪肉价格网并获取Json数据
- AQS(抽象队列同步器)
- CSTC-2017-Web-writeup
- spark 在yarn模式下提交作业