题意:从 节点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算法)的更多相关文章

  1. 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 ...

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

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

  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. MapReudce源码分析之Mapper

    Mapper是MapReduce编程模型中一个将输入的key/value对映射成一组中间key/value对的组件.Map是将输入记录转换成中间记录的单个任务.被转换的中间记录不需要与输入记录一样的类 ...

  2. Highways - poj 2485 (Prim 算法)

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24383   Accepted: 11243 Description T ...

  3. GIS开发站点收藏

    Arcgis API for Silverlight ArcGIS API for Silverlight开发入门 C#开发ArcGIS

  4. 简单的积雪shader

    // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject' Shader "Custom/CoverSnow&q ...

  5. 中国程序员如何去 Facebook 工作?

    1.在Facebook,可以选择哪里工作? Facebook 在内地确实没有 Office ,但可以在https://www.facebook.com/careers/?ref=pf#location ...

  6. 列表按照字母排序检索SideBar

    项目中要求列表按照ABCD这种字母排序检索的功能,看了大神写的,瞬间崇拜了,接下来借大家参考参考了 首先是自定义view sidebar /** * @author J *一个自定义view 实现a- ...

  7. 【python】-- try except (异常捕获)、断言

    try except (异常捕获) 当程序出错了,但是我们又不想让用户看到这个错误,而且我在写程序的时候已经预料到了它可以出现这样的错误,出现这样的错误代表着什么,我们可以提前捕获这些个错误 1.异常 ...

  8. Android笔记之OnLongClickListener

    OnLongClickListener中的回调函数boolean onLongClick(View v),其返回值的官方释义如下 如果这个回调消耗了长点击,则返回true,否则返回false. 即使翻 ...

  9. Js数组的map,filter,reduce,every,some方法

    var arr=[1,2,3,4,5,6]; res = arr.map(function(x){return x*x}) [1, 4, 9, 16, 25, 36] res = arr.filter ...

  10. Codeforces Round #254 (Div. 2)B. DZY Loves Chemistry

    B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...