UVa 291 The House Of Santa Claus 回溯dfs

题意:从左下方的1开始,一笔画出圣诞老人的房子。

 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 int edge[6][6];
 5
 6 //已画了k条边 准备将端点x加入进来
 7 void dfs(int x,int k,string s){
 8     s+=char(x+‘0‘);
 9     if(k==8){
10         cout<<s<<endl;
11         return;
12     }
13     for(int y=1;y<=5;y++){
14         if(edge[x][y]){
15             edge[x][y]=edge[y][x]=0;
16             dfs(y,k+1,s);
17             edge[x][y]=edge[y][x]=1;
18         }
19     }
20 }
21 int main(){
22     memset(edge,0,sizeof(edge));
23     for(int i=1;i<=5;i++){
24         for(int j=1;j<=5;j++){
25             if(i!=j)
26                 edge[i][j]=1;
27         }
28     }
29     edge[4][1]=edge[1][4]=0;//1、4  2、4不相连
30     edge[4][2]=edge[2][4]=0;
31     dfs(1,0,"");
32     return 0;
33 }

原文地址:https://www.cnblogs.com/noobimp/p/10340193.html

时间: 2024-08-28 08:03:39

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

291 - The House Of Santa Claus

来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=4&problem=227&mosmsg=Submission+received+with+ID+14026069 The House Of Santa Claus In your childhood you most likely had to solve the ri

UVA 291

A - The House Of Santa Claus(11.2.1)) Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description In your childhood you most likely had to solve the riddle of the house of Santa Claus. Do

[2015-12-24]OMG美语每日笔记-Santa Claus

坚持学习英语,OMG口语非常长不错,坚持每天整理.学英语坚持最重要,学英语坚持最重要,学英语坚持最重要说三遍! Santa Claus is coming to town 圣诞老人进城来! There are so many Christmas songs about Santa .Santa Claus is coming to town.Is a classic example. 关于圣诞老人的歌很多,圣诞老人进城来,是一个比较经典的歌. Santa Baby 圣诞宝贝 I love lis

uva 639 Don&#39;t Get Rooked (暴力回溯 )

uva 639 Don't Get Rooked In chess, the rook is a piece that can move any number of squares vertically or horizontally. In this problem we will consider small chess boards (at most 44) that can also contain walls through which rooks cannot move. The g

【Codeforces748D】Santa Claus and a Palindrome [STL]

Santa Claus and a Palindrome Time Limit: 20 Sec  Memory Limit: 512 MB Description 有k个串,串长都是n,每个串有一个ai的贡献. 选出若干个串,若它们可以通过任意组合,形成一个回文串,则可以获得它们的贡献之和. 求最大贡献. Input 第一行两个整数k,n. 之后k行,每行分别是一个串si,与贡献ai. Output 一个整数表示答案. Sample Input 7 3 abb 2 aaa -3 bba -1 z

Uva 12009 平方数尾数与自身相同 dfs 构造

题目链接:点击打开链接 题意:rt 思路:从最低位开始构造,若x位的平方数是自身则继续构造. mark: #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<stack>

Uva 110 - Meta-Loopless Sorts(!循环,回溯!)

题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=46  Meta-Loopless Sorts  Background Sorting holds an important place in computer science. Analyzing and implementing various so

uva 539 The Settlers of Catan(回溯)

uva 539 The Settlers of Catan Within Settlers of Catan, the 1995 German game of the year, players attempt to dominate an island by building roads, settlements and cities across its uncharted wilderness. You are employed by a software company that jus