UVA - 539 The Settlers of Catan
2014-10-21 19:01
369 查看
题目大意:给你N个点,M个相连接的路径,在每条路只能走一次的条件下,求最长的路径是多少
解题思路:用回溯法,简单暴力
解题思路:用回溯法,简单暴力
#include<cstdio> #include<cstring> int n, m; int node[50][50]; int max; void dfs(int cur, int len) { for(int j = 0; j < n; j++){ if(node[cur][j]) { node[cur][j]--; node[j][cur]--; dfs(j,len+1); node[cur][j]++; node[j][cur]++; } } if(max < len) max = len; } int main() { int num1, num2; while(scanf("%d%d", &n, &m) && m) { memset(node,0,sizeof(node)); for(int i = 0; i < m; i++) { scanf("%d %d",&num1,&num2); node[num1][num2]++; node[num2][num1]++; } max = 0; for(int i = 0; i < n; i++) dfs(i,0); printf("%d\n",max); } return 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 解题报告
- UVA539- 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