UVA - 539 The Settlers of Catan
来源:互联网 发布:程序员的数学百度网盘 编辑:程序博客网 时间:2024/06/11 17:05
题目大意:n 个点 m 条线,每条线只能经过一次,点不做要求,问最多能经过几条线。
解题思路:无向图,处理的时候两个方向都要标记,起点任意,所以循环一下每个点都做一次起点。然后就是回溯了。
#include<iostream> #include<cstdio>#include<cmath>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;int n, m;bool map[50][50];int ans, tmp;void dfs(int now) { int t = 0; for (int i = 0; i < n; i++) if (map[now][i]) t = 1; if (!t) { if (tmp > ans) ans = tmp; return; } for (int i = 0; i < n; i++) { t = tmp; if (map[now][i]) { tmp++; map[now][i] = false; map[i][now] = false; } else continue; dfs(i); map[now][i] = true; map[i][now] = true; tmp = t; }}int main() { while (scanf("%d%d", &n, &m) != EOF && n+m) { int a, b; memset(map, false, sizeof(map)); for (int i = 0; i < m; i++) { scanf("%d%d", &a, &b); map[a][b] = true; map[b][a] = true; } ans = 0; for (int i = 0; i < n; i++) { tmp = 0; dfs(i); } printf("%d\n", ans); }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
- JVM实用参数(四)内存调优
- Android Nexus私有库搭建
- shell中条件判断if中的-z到-d的意思
- UVA - 639 Don't Get Rooked
- JVM实用参数(八)GC日志
- UVA - 539 The Settlers of Catan
- C#基本程序结构
- android小说阅读器智能断章功能的实现(续)
- IPC之FIFO(有名管道)详解
- android adb破解获取root权限的锁屏密码
- DisableExplicitGC和Direct ByteBuffer
- 线性表的链式存储结构-单链表
- 初学者之小甲鱼C++定义构造器与析构器
- AngularJS之下拉框(方式二)