UVA539- The Settlers of Catan
来源:互联网 发布:淘宝卖家引流技巧 编辑:程序博客网 时间:2024/05/01 23:14
题意:给n个点,给你点与点之间的关系,求出最大的路线
思路:DFS,用深搜,不断更新最大值。。。。
#include<stdio.h> #include<string.h>#define N 30 int n, m, max;int map[N][N];void dfs(int x, int cnt) {if (cnt > max)max = cnt;for(int i = 0; i < n; i++) {if (map[x][i]) {map[x][i] = map[i][x] = 0;dfs(i, cnt + 1);map[x][i] = map[i][x] = 1;}}}int main() { while (scanf("%d %d", &n, &m) != EOF) {int a, b;if (n == 0 && m == 0)break;max = 0;memset(map, 0, sizeof(map));for(int i = 0; i < m; i++) {scanf("%d %d", &a, &b);map[a][b] = 1;map[b][a] = 1;}for(int i = 0; i < n; i++) {dfs(i, 0);}printf("%d\n", max);}return 0;}
- uva539 - The Settlers of Catan
- UVA539- The Settlers of Catan
- [回溯]The Settlers of Catan UVA539
- The Settlers of Catan(uva539简单的回溯)
- The Settlers of Catan
- 539--The Settlers of Catan
- 539The Settlers of Catan
- 539 - The Settlers of Catan
- UVaOJ539 - The Settlers of Catan
- UVA657- The Settlers of Catan
- 539 - The Settlers of Catan
- UVA The Settlers of Catan
- The Settlers of Catan POJ
- zju1947 The Settlers of Catan (DFS)
- UVa 539 The Settlers of Catan
- Uva 539 The Settlers of Catan
- uva 539 - The Settlers of Catan
- uva 539 - The Settlers of Catan
- 服务器端逻辑的迁移
- python property 函数用法
- 基于遗传算法的高校排课系统研究
- ArcGIS 10.2 操作SQLite
- hdu1690 Bus System (dijkstra)
- UVA539- The Settlers of Catan
- UVA657- The Settlers of Catan
- 使用winrar打包文件
- Shell简易学习练习
- 背包问题九讲(转)
- 校招季——操作系统的存储管理
- Java与C#平台通信 WCF CXF SOAP
- 网络验证
- 数学之路(3)-机器学习(3)-机器学习算法-神经网络[18]