好久没写搜索的题目了 复习一下/。/ 这道题目是暴力的全排列
#include<cstdio>
#include<iostream>
#include<cstring>
#define maxn 31
#define inf 1<<29
using namespace std;
int
mapp[maxn][maxn],line[],minn,vis[];
int
k;
int
mymin(int x,int y)
{

if
(x>y) return y;
else return
x;
}

void
dfs(int pos,int time,int cost)
{

if
(time>k)
{

//cout<<minn<<endl;
minn=mymin(minn,cost);
return
;
}

for
(int i=;i<=k;i++)
{

if
(vis[i]) continue;
vis[i]=;
//cout<<i<<' '<<time<<endl;
dfs(i,time+,cost+mapp[line[pos]][line[i]]);
vis[i]=;
}
}

int
main()
{

int
t;
cin.sync_with_stdio(false);
while
(cin>>t&&t)
{

for
(int i=;i<t;i++) for(int j=;j<t;j++) cin>>mapp[i][j];
cin>>k;
for
(int i=;i<=k;i++) cin>>line[i],vis[i]=;
minn=inf;
dfs(,,);
cout<<minn<<endl;
}

return
;
}

hdu 1572 全排列的搜索的更多相关文章

  1. HDU(1572),最短路,DFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1572 很久没写深搜了,有点忘了. #include <iostream> #include ...

  2. HDU 4616 Game (搜索)、(树形dp)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4616 这道题目数据可能比较弱,搜索都可以AC,但是不敢写,哎…… 搜索AC代码: #include & ...

  3. [HDU 2102] A计划(搜索题,典型dfs or bfs)

    A计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. hdu 4722(记忆化搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 思路:简单的记忆化搜索,留意一下A==0时的情况就可以了. #include<iostre ...

  5. hdu 5335 Walk Out (搜索)

    题目链接: hdu 5335 Walk Out 题目描述: 有一个n*m由0 or 1组成的矩形,探险家要从(1,1)走到(n, m),可以向上下左右四个方向走,但是探险家就是不走寻常路,他想让他所走 ...

  6. 51 NOD 1384 全排列(STL 搜索)

    1384 全排列       基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题        收藏        关注   给出一个字符串S(可能又重复的字符),按照字典序 ...

  7. HDU 1896 Stones --优先队列+搜索

    一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...

  8. HDU 1978 记忆化搜索(dfs+dp)

    Y - How many ways Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4597 记忆化搜索

    ² 博弈取牌—记忆化搜索 题目描述: 有两副带有数字的牌,(数字>0)两人轮流取,取中了某张牌,自己的分数就加上牌上的数字,但只能从两端取,每人都会用最优的策略使得自己的分数最高.问A先取,他能 ...

随机推荐

  1. Geth安装和使用

      版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u011680118/article/details/82378509 一.简介 Geth是Go ...

  2. Django中的 返回json对象的方式

    在返回json对象的几种方式: 1 from django.shortcuts import render, HttpResponse # Create your views here. from d ...

  3. WebService技术规则

    1.基于web的系统级接口规范     - 一个普通适用标准 :http+xml     - 任何网络通信的操作系统     - 自包含.自描述.模块化     - 发布.定位.通过web调用  2. ...

  4. C之输入输出

    %d - int%ld – long (long int)%lld - long long%hd – short 短整型 (half int) %c - char%f - float%lf – dou ...

  5. jquery 对svg 元素的addClass removeClass 支持

    jquery 2.2 之后才支持对svg 元素的addClass removeClass

  6. [Scikit-learn] 2.3 Clustering - kmeans

    参考: 2.3. Clustering 2.4. Biclustering 2.1.2.3. The Dirichlet Process Clusering, GMM, Variational Inf ...

  7. Spring Cloud(6):保护微服务(Security) - OAuth2.0

    OAuth2是一个授权(Authorization)协议.我们要和Spring Security的认证(Authentication)区别开来,认证(Authentication)证明的你是不是这个人 ...

  8. word内存不足 解决办法

    word2013内存不足 解决办法具体操作如下: 尝试了很多方法和经验表示都没有效果,最后找到个有效果的分享给大家: 点击“文件”——选项——加载项“   点左下的”管理“-” 转到“ 把加载项前面的 ...

  9. 分布式开发之:id生成器

    一般分布式系统开发中不建议使用数据库自带的自增ID做id. 理由: 1.不方便分库分表.(TIDB时代待商榷) 2.不利于多机房多活部署. 那么如果不使用数据库的id.那怎么生成id呢. 1. Twi ...

  10. Lua实现简单的类,继承,多态 实例

    -- 类的例子,长方形的类,具备一个打印面积方法和一个设置长宽的方法 --lua实现类的思路,定义出来的对象在lua中可以访问自己有的成员,访问成员函数实际上是通过元表的__index方法实现的,具体 ...