hdu2181-哈密顿绕行世界
来源:互联网 发布:刘嘉玲网络云盘 编辑:程序博客网 时间:2024/04/30 00:18
#include<stdio.h>#include<algorithm>#include<math.h>#include<string.h>#include<queue>#define maxn 21#define INF 0xfffffffusing namespace std;bool map[maxn][maxn];bool used[maxn];int res[maxn];int num;int cas;void init(){ int a, b, c, i; for (i = 1; i <= 20; i++) { scanf("%d%d%d", &a, &b, &c); map[i][a] = true; map[i][b] = true; map[i][c] = true; }}void dfs(int dep, int count){ int i, j; res[count] = dep; if (count == 19) { if (map[dep][cas]) { printf("%d: ", ++num); for (i = 0; i < 20; ++i) printf("%d ", res[i]); printf("%d\n", res[0]); } return; } for (j = 1; j <= 20; j++) { if (map[dep][j] && !used[j]) { used[j] = true; dfs(j, count + 1); used[j] = false; } }}int main(){ memset(map, 0, sizeof(map)); init(); while (scanf("%d",&cas),cas) { num = 0; memset(used, false, sizeof(used)); memset(res, 0, sizeof(res)); used[cas] = true; dfs(cas, 0); } return 0;}
0 0
- hdu2181-哈密顿绕行世界
- HDU2181:哈密顿绕行世界问题
- hdu2181哈密顿绕行世界问题(DFS)
- HDU2181:哈密顿绕行世界问题(DFS)
- HDU2181:哈密顿绕行世界问题(DFS)
- 哈密顿绕行世界问题(hdu2181)
- HDU2181---哈密顿绕行世界问题
- [dfs]hdu2181 哈密顿绕行世界问题
- 【DFS】HDU2181哈密顿绕行世界问题
- HDU2181哈密顿绕行世界问题
- 【hdu2181】 哈密顿绕行世界问题
- HDU2181 哈密顿绕行世界问题 dfs
- hdu2181 哈密顿绕行世界问题 (dfs)
- Hdu2181 哈密顿绕行世界问题
- HDU2181-哈密顿绕行世界问题
- hdu2181哈密顿绕行世界问题
- hdu2181 哈密顿绕行世界问题【dfs】
- hdu2181哈密顿绕行世界问题
- SecureCRT背景及根据不同文件类型颜色的设置
- QtWayLand
- HTML5+(html5 plus)
- Word Pattern
- 蓝桥杯
- hdu2181-哈密顿绕行世界
- 读取坐标文件(指定格式文件)
- springmvc常用注解标签详解
- 获取指定程序是否在运行
- 1、ActiveMQ 学习记录 之 初次见面
- 每天一个Linux命令(28):tar命令
- linux 下部署nodejs(两种方式)
- POSIX线程-互斥量
- 二叉树 叶子结点 与 度为2的节点关系