UVA - 539 The Settlers of Catan
来源:互联网 发布:南昌java培训费用 编辑:程序博客网 时间:2024/06/05 05:03
题目大意:给你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;}
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
- 任何调试器小错误都不能容忍
- Codeforces Round #273 (Div. 2) D. Red-Green Towers
- MyBatis多参数传递之注解方式示例
- codeforces 431B Shower Line
- 多个iframe同时加载并动态调整大小
- UVA - 539 The Settlers of Catan
- VMware 10.0 + Mac OS X 10.9.5 安装详解
- centos 7安装flash插件
- C语言结构体与枚举等类型
- 为什么会有50万人选择北大青鸟?
- 第k最短路A*启发式搜索
- 简单的中文图片验证码的生成
- jquery UI学习笔记-知问前端之自动补全工具UI的tooltip
- 私服发布Maven