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 ...
随机推荐
- android:分享 一个非常强大的LOG开关---Log.isLoggable
1.API亮点: 此API能够实现不更换APK.在出问题的手机上就直接能抓到有效log,能提升不少工作效率. .API介绍 近期在解决短信问题时.看到一个非常强大的LOG开关---Log.isLogg ...
- Linux高并发应用类型对系统内核的优化
Linux操作系统内核参数优化 net.ipv4.tcp_max_tw_buckets = net.ipv4.ip_local_port_range = net.ipv4.tcp_tw_recycle ...
- FreeSWITCH版本更新
[1]FreeSWITCH版本更新 从2014年10月底开始,FreeSWITCH代码库改为由stash管理,该管理工具能更好地与jira集成. 如果你以前已经clone了代码,请做如下更新: git ...
- mysql 存储过程初探
使用存储过程好处在于: 1.隐藏敏感的算法,避免被正常的开发人员看到,把业务逻辑隐藏在数据库中,而非程序代码里 2.简化应用代码程序,放到数据库里肯定就对程序代码简化有好处了 3.不同的开发语言都可以 ...
- 源码安装Apache,报错:Cannot use an external APR with the bundled APR-util
一般在第一次源码安装是没有问题的,在版本变化情况下在次源码安装可能会遇到此问题: apache2.0.x与apache2.2.x在apr有很大区别,前者为依赖公用apr,后者依赖于自身的apr.一般前 ...
- 微信小程序之如何注册微信小程序
所有文章均是CSDN博客所看,已按照作者要求,注明出处了,感谢作者的整理! 博客文章地址:http://blog.csdn.net/michael_ouyang/article/details/546 ...
- lumen手记:自定义Validate表单验证
版权声明:本文为博主原创文章,未经博主允许不得转载. 今天开始跳lumen的表单验证Validate类的坑,确实好坑!!! 首先,lumen的表单验证返回是无状态的json格式api,这... 所有开 ...
- 二、Android应用的界面编程(六)ProgressBar及其子类[SeekBar、RatingBar]er
通常用于向用户显示某个耗时操作完成的百分比.Android支持几种风格的进度条,通过style属性可以为ProgressBar指定风格.该属性支持如下几个属性值. # @android:style/W ...
- 字符串HASH模板
//注意MAXN是最大不同的HASH个数,一般HASHN是MAXN的两倍左右,MAXLEN表示字符串的最大长度 //K表示正确率,越大正确率越高,当时也越费空间,费时间. //使用前注意初始化hash ...
- EasyNVR流媒体直播之:零基础实现摄像头的全平台直播 (二)公网直播的实现
接上回(https://blog.csdn.net/xiejiashu/article/details/81276870),我们实现内网直播,可以实现直播的web观看,该篇博文我们将实现公网的直播. ...