题目地址:点击打开链接
就是普通的回溯就可以了
#include <iostream> #include <cstring> using namespace std; int graph[30][30]; int n; int max_num; void dfs(int num,int sum) { for(int i=0;i<n;++i) { if(graph[num][i]!=0) { graph[num][i]=graph[i][num]=0; ++sum; if(sum>max_num) max_num=sum; dfs(i,sum); --sum; graph[num][i]=graph[i][num]=1; } } } int main() { int m; while(cin>>n>>m) { if(n==0&&m==0) break; memset(graph,0,sizeof(graph)); for(int i=0;i<m;++i) { int a,b; cin>>a>>b; graph[a][b]=graph[b][a]=1; } max_num=-1; for(int i=0;i<n;++i) dfs(i,0); cout<<max_num<<endl; } return 0; }
UVa539 - The Settlers of Catan,布布扣,bubuko.com
UVa539 - The Settlers of Catan
原文:http://blog.csdn.net/leizh007/article/details/23116995