哈密顿绕行世界问题---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 ...
随机推荐
- xadmin 安装详解
1.安装必要的包 django>=1.9.0 django-crispy-forms>=1.6.0 django-import-export>=0.5.1 django-revers ...
- Django And Django-Rest-Framework 异常记录
1.TypeError: init() takes 1 positional argument but 2 were given
- 决Ubuntu使用`make menuconfig`配置Linux 内核时,出现缺少'ncurses-devel'库支持。
*** Unable to find the ncurses libraries or the *** required header files. *** 'make menuconfig' req ...
- ajax——实现三级联动下拉列表
数据库: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...
- java调用kettle_实现(2)
(1).参照“java调用kettle_导入jar包(1)”,应用etl工具下lib里的所有jar (2). 最近要对一个系统的数据同步到另一个系统中,要求新系统的数据结果完成之后,实时同步到另一个系 ...
- LandMVC HttpHandler web.config配置
<system.webServer> <validation validateIntegratedModeConfiguration="false" /> ...
- int main(int argc, char *argv[])中的argc和argv
argc 是 argument count的缩写,表示传入main函数的参数个数: argv 是 argument vector的缩写,表示传入main函数的参数序列或指针,并且第一个参数argv[0 ...
- 我的Android进阶之旅------>MIME类型大全
今天在实现一个安装apk的代码中看到一段代码为:application/vnd.android.package-archive.不知其意.所以百度了一下,了解到这是一种MIME的类型,代表apk类型. ...
- 运维角度浅谈:MySQL数据库优化
日志君导读: 一个成熟的数据库架构并非一開始设计就具备高可用.高伸缩等特性的.它是随着用户量的添加,基础架构才逐渐完好. 作者:zhenliang8.本文转自51CTO博客,点击原文阅读查看网页版文章 ...
- sql语句优化 (转)
性能不理想的系统中除了一部分是因为应用程序的负载确实超过了服务器的实际处理能力外,更多的是因为系统存在大量的SQL语句需要优化. 为了获得稳定的执行性能,SQL语句越简单越好.对复杂的SQL语句,要设 ...