UVA 539 The Settlers of Catan dfs找最长链
来源:互联网 发布:淘宝刷单兼职靠谱 编辑:程序博客网 时间:2024/06/04 18:22
题意:画边求最长链,边不能重复数点可以。
很水,用暴力的dfs即可,因为数据不大。
本来以为可以用floyd进行dp的,后来想想好像不能在有回路上的图跑。。。于是没去做。
#include <cstdio>const int maxn = 30;int e[maxn][maxn];int vis[maxn][maxn];int n, m, max;void dfs(int x, int d) {if (max < d)max = d;for (int i = 0; i < n; i++)if (!vis[x][i] && e[x][i]) {vis[x][i] = vis[i][x] = 1;dfs(i, d + 1);vis[x][i] = vis[i][x] = 0;}}int main() {while (scanf("%d%d", &n, &m) && n && m) {max = 0;int a, b;for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)vis[i][j] = e[i][j] = 0;for (int i = 0; i < m; i++) {scanf("%d%d", &a, &b);e[a][b] = e[b][a] = 1;}for (int i = 0; i < m; i++)dfs(i, 0);printf("%d\n", max);}//whilereturn 0;}
- UVA 539 The Settlers of Catan dfs找最长链
- UVA 539-The Settlers of Catan(dfs)
- The Settlers of Catan uva dfs+回溯
- UVA 539 The Settlers of Catan dfs无向图最长路
- UVa - 539 - 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
- 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
- ZOJ Problem Set - 1016 parencodings
- ZTe v889d 双卡双待手机,不需要ROOT就使用卡2实现上网。(仅测试了安卓4.0版本)
- C#数据类型转换的几种形式
- 获取MAC中的IP地址
- URAL 1136 Parliament 二叉树水题 BST后序遍历建树
- UVA 539 The Settlers of Catan dfs找最长链
- JQ选项卡
- Jquery8_简单的动画效果
- ubuntu linux命令行下安装sublime text 2
- 19-textarea知识
- Beef up Web search applications with Lucene Improve searches with a more robust app from the Apach
- jAVA
- POS
- myeclipse8.5如何安装jadeclipse详解