UVA 539 - The Settlers of Catan
来源:互联网 发布:2016最新网络歌曲 编辑:程序博客网 时间:2024/05/04 02:32
题目大意:给你 N 个结点, M 条路, 求一条最长的路,这条路不能经过一个结点两次
解题思路:直接 DFS ,探索所有可能的路,记录下最长的那条
#include <cstdio>int node[30] = {0}, road[30][2], n, m, max, count = 0;int dfs(int num) {bool end = true;for (int i = 0; i < m; i++)if ((road[i][0] == num || road[i][1] == num) && node[i] == 0) { //寻找连接此结点的路end = false; //假如此结点能连接下一个结点则说明此结点不是终点node[i] = 1; //标记此结点已走过count++;dfs(road[i][0] == num ? road[i][1] : road[i][0]); //探索连接了此结点的路的另一端点node[i] = 0;count--;}if (end && count > max)max = count;}int main () {while (scanf("%d%d", &n, &m), n) {max = 0;for (int i = 0; i < m; i++)scanf("%d%d", &road[i][0], &road[i][1]);for (int i = 0; i < n; i++) //从各个结点出发,探索线路dfs(i);printf("%d\n", max);}return 0;}
0 0
- UVa 539 The Settlers of Catan
- Uva 539 The Settlers of Catan
- uva 539 - The Settlers of Catan
- uva 539 - The Settlers of Catan
- uva 539 - The Settlers of Catan
- UVa 539 - The Settlers of Catan
- UVA 539 - The Settlers of Catan
- UVa 539 - The Settlers of Catan
- uva 539 The Settlers of Catan
- uva 539 - The Settlers of Catan
- UVA 539 The Settlers of Catan
- uva 539 The Settlers of Catan
- UVA 539 The Settlers of Catan
- uva 539 The Settlers of Catan
- UVa 539 - The Settlers of Catan
- uva 539 - The Settlers of Catan
- uva 539 The Settlers of Catan
- UVa 539 The Settlers of Catan
- 机房收费系统之报表(二)
- 10点半游戏(改编)
- 大数据:“人工特征工程+线性模型”的尽头
- 在Windows下读取Ext4分区
- hdu1425.sort
- UVA 539 - The Settlers of Catan
- 机器学习是什么--周志华
- Valid Parentheses
- 探索tinyxml的编译
- Text Reverse hdoj 1062
- error:structure required on left side of . or .*
- 【DP】 HDOJ 4939 Stupid Tower Defense
- C数据类型引发的安全隐患
- 程序员既要写好代码,又要写好文档