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(,,"");
}
UVA 291 The House Of Santa Claus DFS的更多相关文章
- UVA 291 The House Of Santa Claus (DFS求一笔画)
题意:从左下方1开始,一笔画出圣诞老人的屋子(不过话说,圣诞老人的屋子是这样的吗?这算是个屋子么),输出所有可以的路径. 思路:贴代码. #include <iostream> #incl ...
- UVA 291 The House Of Santa Claus(DFS算法)
题意:从 节点1出发,一笔画出 圣诞老人的家(所谓一笔画,就是遍访所有边且每条边仅访问一次). 思路:深度优先搜索(DFS算法) #include<iostream> #include&l ...
- UVa 291 The House Of Santa Claus——回溯dfs
题意:从左下方的1开始,一笔画出圣诞老人的房子. #include <iostream> #include <cstring> using namespace std; ][] ...
- E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- codeforces 748E Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 依赖注入在 dotnet core 中实现与使用:2 使用 Extensions DependencyInjection
既然是依赖注入容器,必然会涉及到服务的注册,获取服务实例,管理作用域,服务注入这四个方面. 服务注册涉及如何将我们的定义的服务注册到容器中.这通常是实际开发中使用容器的第一步,而容器本身通常是由框架来 ...
- 软件设计之基于Java的连连看小游戏(二)——游戏基础界面的制作及事件的添加
上次完成到游戏首页的制作,今天完成了游戏基础界面的制作以及事件的简单添加.由于功能尚未完全实现,因此游戏界面的菜单列表只是简单地添加了一下,其余菜单列表以及倒计时等在后续的制作中逐一完善. 1.首先在 ...
- Python的包package的导入与被导入(包的类和方法的导入,__init__()怎么写)
包package的导入与被导入: 参考一下: https://blog.csdn.net/guowujun321/article/details/80764468 1.文件目录: | |-- A/ ...
- ucoreOS_lab7 实验报告
所有的实验报告将会在 Github 同步更新,更多内容请移步至Github:https://github.com/AngelKitty/review_the_national_post-graduat ...
- Redis主从复制机制详解
Redis主从复制机制详解 Redis有两种不同的持久化方式,Redis服务器通过持久化,把Redis内存中持久化到硬盘当中,当Redis宕机时,我们重启Redis服务器时,可以由RDB文件或AOF文 ...
- MySQL数据库无法使用+号连接字符串的处理方法
转自:http://www.maomao365.com/?p=10003 摘要: 下文讲述MySQL数据库,字符串连接的方法分享,如下所示:实现思路: 使用concat函数对两个字符串进行连接在MyS ...
- unbuntu更换软件源
编辑/etc/apt/sources.list文件,将文件中原有的国外源全部注释掉,文件头添加以下内容 ##中科大源 deb https://mirrors.ustc.edu.cn/ubuntu/ b ...
- Linux:使用LVM进行磁盘管理
LVM的概念 LVM 可以实现对磁盘的动态管理,在磁盘不用重新分区的情况下动态调整文件系统的大 小,利用 LVM 管理的文件系统可以跨越磁盘. "/boot"分区用于存放系统引导文 ...
- 17.Java基础_初探类的private和public关键字
package pack1; public class Student { // 成员变量 private String name; private int age; // get/set方法 pub ...
- 【cf343】D. Water Tree(dfs序+线段树)
传送门 题意: 给出一个以\(1\)为根的有根树,起始每个结点都为\(0\),现在有三种操作: 1.将\(v\)及\(v\)的子树都置为\(1\): 2.将\(v\)及其所有的祖先都置为\(0\): ...