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 ...
随机推荐
- 史上最全的Java命名规范[转]
每个公司都有不同的标准,目的是为了保持统一,减少沟通成本,提升团队研发效能.所以本文中是笔者结合阿里巴巴开发规范,以及工作中的见闻针对Java领域相关命名进行整理和总结,仅供参考. 一.Java中的命 ...
- mysql 常用命令行总结
登录 mysql -h -u root -p 回车后输入密码,即可登录 直接进入某个库 -D 库名 mysql -h -u root -D account -p 列举数据库.表 show databa ...
- 前端之CSS1
CSS基本语法和引入方式 CSS介绍 为了让网页元素的样式更加丰富,也为了让网页的内容和样式能拆分开,CSS由此而诞生,CSS是 Cascading Style Sheets 的首字母缩写,意思是层叠 ...
- GitHub 2019年年度报告:Python最受欢迎,VScode贡献者高达19.1K
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 开源最前线(ID:OpenSourceTop) PS:如有需要Pyt ...
- 用ggplot包画一个简单饼图
首先用library函数加载ggplot2包 library(ggplot2) library(dplyr) library(tidyr) library(splines) 接下来,进行数据准备: d ...
- 性能篇系列—stream详解
Stream API Java 8集合中的Stream相当于高级版的Iterator Stream API通过Lambda表达式对集合进行各种非常便利高效的聚合操作,或者大批量数据操作 Stream的 ...
- 【转载】Android 的 Handler 机制实现原理分析
handler在安卓开发中是必须掌握的技术,但是很多人都是停留在使用阶段.使用起来很简单,就两个步骤,在主线程重写handler的handleMessage( )方法,在工作线程发送消息.但是,有没有 ...
- [20190531]ORA-600 kokasgi1故障模拟与恢复.txt
[20190531]ORA-600 kokasgi1故障模拟与恢复.txt --//昨天看链接:http://www.xifenfei.com/2019/05/ora-600-kokasgi1-rec ...
- JAVA框架中XML文件
其实在JAVA开发中servlet配置,映射注入配置等等都可以用xml来配置 在此处的department是实体类的名字,而不是对应的数据库表的名字 数据库表的字段名=#{实体类属性名} 逆向工程生成 ...
- 修改Tooltip 文字提示 的背景色 箭头颜色
3==>vue 鼠标右击<div @contextmenu.prevent="mouseRightClick">prevent是阻止鼠标的默认事件 4==> ...