题目:

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(,,"");
}

UVA 291 The House Of Santa Claus DFS的更多相关文章

  1. UVA 291 The House Of Santa Claus (DFS求一笔画)

    题意:从左下方1开始,一笔画出圣诞老人的屋子(不过话说,圣诞老人的屋子是这样的吗?这算是个屋子么),输出所有可以的路径. 思路:贴代码. #include <iostream> #incl ...

  2. UVA 291 The House Of Santa Claus(DFS算法)

    题意:从 节点1出发,一笔画出 圣诞老人的家(所谓一笔画,就是遍访所有边且每条边仅访问一次). 思路:深度优先搜索(DFS算法) #include<iostream> #include&l ...

  3. UVa 291 The House Of Santa Claus——回溯dfs

    题意:从左下方的1开始,一笔画出圣诞老人的房子. #include <iostream> #include <cstring> using namespace std; ][] ...

  4. E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. codeforces 748E Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  6. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  7. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  8. Codeforces Round #389 Div.2 E. Santa Claus and Tangerines

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. Codeforces Round #389 Div.2 D. Santa Claus and a Palindrome

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. javaScript之基础介绍

    前言一:javascript历史背景介绍 布兰登 • 艾奇(Brendan Eich,1961年-),1995年在网景公司,发明的JavaScript. 一开始JavaScript叫做LiveScri ...

  2. C++ 运行时类别识别

    运行时动态类型的识别其实应该是多态方面的知识,这里我直接拿来单独成章. dynamic_cast和static_cast 1.static_cast用法如下: static_cast < Typ ...

  3. 公益:开放一台Nacos服务端给各位Spring Cloud爱好者

    之前开放过一台公益Eureka Server给大家,以方便大家在阅读我博客中教程时候做实验.由于目前在连载Spring Cloud Alibaba,所以对应的也部署了一台Nacos,并且也开放出来,给 ...

  4. Z从壹开始前后端分离【 .NET Core2.2/3.0 +Vue2.0 】框架之六 || API项目整体搭建 6.1 仓储+服务+抽象接口模式

    本文梯子 本文3.0版本文章 前言 零.完成图中的粉色部分 2019-08-30:关于仓储的相关话题 一.创建实体Model数据层 二.设计仓储接口与其实现类 三.设计服务接口与其实现类 四.创建 C ...

  5. 浅谈Java面向对象思想

    本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...

  6. java基础第十四篇之Map

    一,Map集合的特点: *  * 1.Map集合和Collection集合,没有关系 *  * 2.Map集合的元素是成对存在(夫妻关系) *         Collection集合的元素是独立存在 ...

  7. html5+css+js简单了解

    最近敲了敲HTML5的代码,感觉真的是很吸引人的东西,反正我是非常喜欢的,所以想写一点关于HTML的东xi首先呢我了解的不多,所以也是想写一点点我对它的认识.说起HTML5是打开Pycharm敲pyt ...

  8. 使用JAVAScript技术在WEB网页实现摇一摇的应用

    实现效果如下: 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  9. JavaScript—字符串(String)用法

    字符串(String)去除空格 str = " hello python " // 去除左空格: str=str.replace( /^\s*/, ''); // 去除右空格: s ...

  10. 在Rust中使用C语言的库功能

    主要是了解unsafe{}语法块的作用. #[repr(C)] #[derive(Copy, Clone)] #[derive(Debug)] struct Complex { re: f32, im ...