【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

预处理一下终点能到达哪些点。
暴力就好。
输出结果的时候,数字之间一个空格。。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
*/
#include <bits/stdc++.h>
using namespace std; const int N = 30; int k;
int g[N+10][N+10];
bool can[N+10];
int a[N+10];
int vis[N+10],total; void dfs(int x){
if (can[x]) return;
can[x] = 1;
for (int i = 0;i <= N;i++)
if (g[x][i]) dfs(i);
} void dfs1(int x,int dep){
if (x==k){
total++;
cout <<1;
for (int i = 1;i < dep;i++){
cout <<' '<<a[i];
}
cout << endl;
return;
}
vis[x] = true;
if (!can[x]) return;
for (int i = 0;i <= N;i++)
if (g[x][i] && !vis[i]){
a[dep] = i;
dfs1(i,dep+1);
}
vis[x] = false;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int kase = 0;
while (cin >> k){
total = 0;
cout <<"CASE "<<++kase<<":"<<endl; memset(can,0,sizeof can);
memset(g,0,sizeof g);
int x,y;
while(cin >> x >> y){
if (x==0 && y==0) break;
g[x][y] = 1;
g[y][x] = 1;
}
dfs(k);
memset(vis,0,sizeof vis);
a[0] = 1;
dfs1(1,1);
cout <<"There are "<<total<<" routes from the firestation to streetcorner "<<k<<"."<<endl;
}
return 0;
}

【习题 7-1 UVA-208】Firetruck的更多相关文章

  1. Uva 208 - Firetruck

    [题目链接]http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&p ...

  2. UVa 208 - Firetruck 回溯+剪枝 数据

    题意:构造出一张图,给出一个点,字典序输出所有从1到该点的路径. 裸搜会超时的题目,其实题目的数据特地设计得让图稠密但起点和终点却不相连,所以直接搜索过去会超时. 只要判断下起点和终点能不能相连就行了 ...

  3. UVA - 208 Firetruck(消防车)(并查集+回溯)

    题意:输入着火点n,求结点1到结点n的所有路径,按字典序输出,要求结点不能重复经过. 分析:用并查集事先判断结点1是否可以到达结点k,否则会超时.dfs即可. #pragma comment(link ...

  4. UVA - 208 Firetruck(并查集+dfs)

    题目: 给出一个结点d和一个无向图中所有的边,按字典序输出这个无向图中所有从1到d的路径. 思路: 1.看到紫书上的提示,如果不预先判断结点1是否能直接到达结点d,上来就直接dfs搜索的话会超时,于是 ...

  5. UVa 208 Firetruck【回溯】

    题意:给出一个n个节点的无向图,以及某个节点k,按照字典序从小到大输出从节点1到节点k的所有路径 看的题解 http://blog.csdn.net/hcbbt/article/details/975 ...

  6. 习题7-1 uva 208(剪枝)

    题意:按最小字典序输出a到b 的所有路径. 思路:先处理出个点到目标点b的情况(是否能到达),搜索即可. 最开始我只判了a能否到b,然后给我的是WA,然后看了半天感觉思路没什么问题,然后把所有点都处理 ...

  7. 【UVa】208 Firetruck(dfs)

    题目 题目     分析 一开始不信lrj的话,没判联通,果然T了. 没必要全部跑一遍判,只需要判断一下有没有点与n联通,邻接表不太好判,但无向图可以转换成去判n与什么联通. 关于为什么要判,还是因为 ...

  8. UVa 208 消防车(dfs+剪枝)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. UVA 208 (DFS)

    题意:找出1到T的所有路径: 坑点:一开始以为是到终点,读错了题意,没测试第二个样例,结果WA了4遍,坑大了: #include <iostream> #include <cmath ...

  10. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

随机推荐

  1. IIS Modules Overview

    Introduction The IIS 7 and above Web server feature set is componentized into more than thirty indep ...

  2. thinkphp使后台的字体图标显示异常

    thinkphp使后台的字体图标显示异常 相似问题 1.thinkPHP的这些图标都不显示了-CSDN论坛https://bbs.csdn.net/topics/391823415 解答: 发现在别的 ...

  3. HDU 4372 Count the Buildings

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  4. JS的解析与执行过程—全局预处理阶段之全局词法环境对象

    问题:有如下代码 var a = 1; function pop() { alert(a); var a = 5; } pop();//执行结果,弹出undefined 这段代码的执行结果为undef ...

  5. 【Uva 1630】Folding

    [Link]: [Description] 你能对字符串进行压缩的操作; 即把连续出现的相同的子串改成它出现的次数+这个最基本的字符串的形式; 问你这个字符串最短能被压缩得多短; [Solution] ...

  6. HDU——T 1506 Largest Rectangle in a Histogram|| POJ——T 2559 Largest Rectangle in a Histogram

    http://acm.hdu.edu.cn/showproblem.php?pid=1506  || http://poj.org/problem?id=2559 Time Limit: 2000/1 ...

  7. 【Tika基础教程之中的一个】Tika基础教程

    一.高速入门 1.Tika是一个用于文本解释的框架.其本身并不提供不论什么的库用于解释文本,而是调用各种各样的库,如POI,PDFBox等. 使用Tika.能够提取文件里的作者.标题.创建时间.正文等 ...

  8. 深入理解javascript之高级定时器

    setTimeout()和setInterval()能够用来创建定时器.其主要的用法这里就不再做介绍了.这里主要介绍一下javascript的代码队列. 在javascript中没有不论什么代码是马上 ...

  9. ubuntu-删除内核

    今天进入公司第一天,公司需要给电脑安装ubuntu,这个是由it部门帮忙安装的.但是,我不小心升级了内核版本,接下来就悲剧了,因为内核版本升级以后,直接导致了环境错误,很多公司内部使用的工具都不能用了 ...

  10. C#中结构struct的使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...