UVA 539 - The Settlers of Catan 解题报告
2013-08-05 18:15
393 查看
搜索即可,图为无向图。找出能走的不重复的边的最大数
#include <iostream> #include<cstring> #include<algorithm> #include<fstream> #define maxn 30 using namespace std; int map[maxn][maxn]; int vis[maxn][maxn]; int point_num; int edge_num; int max_num; void dfs(int n,int num) { if(num>max_num) max_num=num; for(int i=0;i<point_num;i++) { if(i!=n&&!vis [i]&&map [i]) { vis [i]=1; vis[i] =1; dfs(i,num+1); vis [i]=0; vis[i] =0; } } } int main() { while(cin>>point_num>>edge_num) { if(0==point_num&&0==edge_num) break; memset(map,0,sizeof(map)); memset(vis,0,sizeof(vis)); max_num=0; for(int i=0;i<edge_num;i++) { int a,b; cin>>a>>b; map[a][b]=1; map[b][a]=1; } for(int i=0;i<point_num;i++) { dfs(i,0); } cout<<max_num<<endl; } 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
- 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(dfs)
- UVA 539 The Settlers of Catan
- UVA - 539 The Settlers of Catan