哈密顿绕行世界问题---hdu2181(全排列问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181
题意很容易理解,dfs就可以了
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <queue>
#include <map>
#include <vector> using namespace std; typedef long long LL; #define met(a, b) memset(a, b, sizeof(a))
#define INF 0x3f3f3f3f
#define N 25 int G[N][N], A[N], vis[N], t; void dfs(int s, int k)
{
if(k == )
{
if( G[A[]][A[]] )
{
A[] = A[]; printf("%d: ", t++); for(int i=; i<=; i++)
printf(" %d", A[i]); printf("\n");
}
return;
}
for(int i=; i<=; i++)
{
if( G[s][i] && !vis[i])
{
A[k] = i; vis[i] = ; dfs(i, k+); vis[i] = ;
}
}
} int main()
{
int a, b, c, m; met(G, ); for(int i=; i<=; i++)
{
scanf("%d %d %d", &a, &b, &c); G[i][a] = G[i][b] = G[i][c] = ;
} while(scanf("%d", &m), m)
{
t = ; met(vis, ); met(A, ); A[] = m; vis[m] = ; dfs(m, );
}
return ;
}
哈密顿绕行世界问题---hdu2181(全排列问题)的更多相关文章
- 哈密顿绕行世界问题 HDU2181
题目大意都比较简单,用vector存一下图,然后爆搜就可以了. #include<bits/stdc++.h> using namespace std; ; vector<]; bo ...
- HDU2181:哈密顿绕行世界问题(DFS)
哈密顿绕行世界问题 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- 哈密顿绕行世界问题(hdu2181)
哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Hdu2181 哈密顿绕行世界问题 2017-01-18 14:46 45人阅读 评论(0) 收藏
哈密顿绕行世界问题 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- HDU2181 哈密顿绕行世界问题 —— DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181 哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) ...
- 【HDU - 2181】哈密顿绕行世界问题(dfs+回溯)
-->哈密顿绕行世界问题 Descriptions: 一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市. Input 前2 ...
- HDU 2181 哈密顿绕行世界问题(经典DFS+回溯)
哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDOJ 2181 哈密顿绕行世界问题
哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2181 哈密顿绕行世界问题 (DFS)
哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- 基于 html5的 jquery 轮播插件 flickerplate
https://github.com/chrishumboldt/Flickerplate 官网 <link href="${baseURL}/themes/default/css/f ...
- Netty中的那些坑
Netty中的那些坑(上篇) 最近开发了一个纯异步的redis客户端,算是比较深入的使用了一把netty.在使用过程中一边优化,一边解决各种坑.儿这些坑大部分基本上是Netty4对Netty3的改进部 ...
- redis-stat 安装
apt-get install ruby apt-get install rubygems redis-stat安装: cd/root git clone https://github.com ...
- [转]使用rosbridge协议实现安卓跟ros的解耦
安卓与ROS通信的现状 因为ROS官方支持的语言绑定只有C++和Python,所以目前安卓想与ROS通信,必须借助半官方的rosjava包,而Rosjava太重了,因为它跟C++/Python一样,是 ...
- jrtplib编译指南
The library offers support for the Real-time Transport Protocol (RTP), The library uses the JThread ...
- BI开发之——Mdx基础语法(2)(转至指尖流淌)
结合webcast中老师的讲解,现在把基础语法应用通过几个案例应用如下: 一.维度的概念 上图中一个维度(Dimension):Region 改为度下有四个级别(Levels):country.pro ...
- C++ const关键字修饰引用
//const修饰引用的两种用法 #include<iostream> using namespace std; struct Teacher{ ]; int age; }; void S ...
- 【BZOJ】1024: [SCOI2009]生日快乐(dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1024 果然现在弱到连搜索都不会了么..... 一直想二分...但是无论如何也推不出怎么划分... Q ...
- 【BZOJ】1625: [Usaco2007 Dec]宝石手镯(01背包)
http://www.lydsy.com/JudgeOnline/problem.php?id=1625 太水了. #include <cstdio> #include <cstri ...
- ThinkPHP跳转与重定向的区别
跳转: 浏览器认为: 当前URL请求成功, 重新请求新的URL. 浏览器会 记录当前的URL 和 新的URL 在请求历史记录中. 回退, 是可以回退到, 当前的URL上的. (无论 success, ...