UVA 291 The House Of Santa Claus(DFS算法)
题意:从 节点1出发,一笔画出 圣诞老人的家(所谓一笔画,就是遍访所有边且每条边仅访问一次)。
思路:深度优先搜索(DFS算法)
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int map[6][6];
void makemap(){
memset(map,0,sizeof(map));
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j++) if(i!=j) map[i][j]=1;
map[4][1]=map[1][4]=0;
map[4][2]=map[2][4]=0;
}
void dfs(int x,int k,string s){ // x 为 出发点/经过点,k为边的条数,s记录路径
s+=char(x+'0');
if(k==8){
cout<<s<<endl;
return ;
}
for(int y=1;y<=5;y++)
if(map[x][y]){
map[x][y]=map[y][x]=0;//画过的的边标记为 0
dfs(y,k+1,s);
map[x][y]=map[y][x]=1;//递归完之后,返回原来未画的状态 1
}
}
int main(){
makemap();
dfs(1,0,"");
return 0;
}
UVA 291 The House Of Santa Claus(DFS算法)的更多相关文章
- 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 re ...
- UVA 291 The House Of Santa Claus (DFS求一笔画)
题意:从左下方1开始,一笔画出圣诞老人的屋子(不过话说,圣诞老人的屋子是这样的吗?这算是个屋子么),输出所有可以的路径. 思路:贴代码. #include <iostream> #incl ...
- 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 ...
随机推荐
- 玩转JPA(一)---异常:Repeated column in mapping for entity/should be mapped with insert="false" update="fal
近期用JPA遇到这样一个问题:Repeated column in mapping for entity: com.ketayao.security.entity.main.User column: ...
- 趣味编程:C#中Specification模式的实现(参考答案 - 下)
一篇文章中我们利用C#语言的特性实现了一种轻量级的Specification模式,它的关键在于抛弃了具体的Specification类型,而是使用一个委托对象代替唯一关键的IsSatisfiedBy方 ...
- PHP-Manual的学习----【语言参考】----【类型】-----【array数组】
1.Array 数组 PHP 中的 数组 实际上是一个有序映射.映射是一种把 values 关联到 keys 的类型.此类型在很多方面做了优化,因此可以把它当成真正的数组,或列表(向量),散列表(是 ...
- Linux中的关机
我是用普通用户登录,在终端下输入shutdown命令,结果显示 command not found.这就奇怪了,难道我的linux不支持这个命令?man了一下shutdown,大篇幅的说明告诉我,我的 ...
- Idea 远程调试jenkins 项目
1.Jenkins配置 jenkins 服务启动时 需要在jvm启动项里加入如下代码: -Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y ...
- TP框架的增删改
TP添加数据有三种方式 1. //1.使用数组添加 $n = M("nation"); $arr = array("Code"=>"n007&q ...
- proxool连接池 异常
这是第二次整理这个文章: 首先说明proxool连接池有两种配置方式: 第一种:采用jdbc.properties的方式 第二种:采用proxool.xml的配置方 后面在完善这两种配置方式(在上班哦 ...
- SpringMVC拦截器实现登录认证
项目结构如图: 需要的jar:有springMVC配置需要的jar和jstl需要的jar SpringMVC包的作用说明: aopalliance.jar:这个包是AOP联盟的API包,里面包含了针对 ...
- ArcGIS API for js InfoWindow
说明:有关该示例中怎么引用部署在iis上的离线arcgis api请参考我前面的博文 1.运行效果 2.HTML代码 <!DOCTYPE html> <html> <he ...
- tomcat 编码问题
默认情况下,tomcat使用的的编码方式:iso8859-1 修改tomcat下的conf/server.xml文件 找到如下代码: < Connector port="8080 ...