题目链接:http://poj.org/problem?id=3311

题目大意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小。

Sample Input

3
0 1 10 10
1 0 1 2
10 1 0 10
10 2 10 0
0

Sample Output

8

分析:dp[i][j]:表示在i状态(用二进制表示城市有没有经过)时最后到达j城市的最小时间,转移方程:dp[i][j]=min(dp[i][k]+d[k][j],dp[i][j])  d[k][j]是k城市到j城市的最短距离,显然要先用flody处理一下。

代码如下:
 # include<stdio.h>
# include<string.h>
int map[][],n,m,dp[<<][];
const int INF = <<; int min(int a,int b){
return a<b ?a :b;
} void flody(){
int i,j,k;
for(k=; k<=n; k++)
for(i=; i<n; i++)
for(j=; j<=n; j++){
if(map[i][k] + map[k][j] < map[i][j])
map[i][j] = map[i][k] + map[k][j];
}
}
int main(){
int i,j,k;
while(scanf("%d",&n) && n){
for(i=; i<=n; i++)
for(j=; j<=n; j++)
scanf("%d",&map[i][j]);
flody();
int ans = INF;
for(i=; i<(<<n); i++)
for(j=; j<=n; j++)
if(i==(<<(j-)))
dp[i][j] = map[][j];
else
if(i & (<<(j-))){
dp[i][j] = INF;
for(k=; k<=n; k++)
if(k!=j && (i & (<<(k-))))
dp[i][j] = min(dp[i^(<<(j-))][k] + map[k][j],dp[i][j]);
}
for(i=; i<=n; i++)
ans = min(ans, dp[(<<n)-][i]+map[i][]);
printf("%d\n",ans);
}
return ;
}
 

POJ 3311 Hie with the Pie(DP状态压缩+最短路径)的更多相关文章

  1. POJ 3311 Hie with the Pie(Floyd+状态压缩DP)

    题是看了这位的博客之后理解的,只不过我是又加了点简单的注释. 链接:http://blog.csdn.net/chinaczy/article/details/5890768 我还加了一些注释代码,对 ...

  2. poj 3311 Hie with the Pie(状态压缩dp)

    Description The Pizazz Pizzeria prides itself or more (up to ) orders to be processed before he star ...

  3. poj 3311 Hie with the Pie dp+状压

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4671   Accepted: 2471 ...

  4. poj 3311 Hie with the Pie

    floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Me ...

  5. poj 3311 Hie with the Pie (TSP问题)

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4491   Accepted: 2376 ...

  6. POJ 3311 Hie with the Pie(状压DP + Floyd)

    题目链接:http://poj.org/problem?id=3311 Description The Pizazz Pizzeria prides itself in delivering pizz ...

  7. POJ 3311 Hie with the Pie floyd+状压DP

    链接:http://poj.org/problem?id=3311 题意:有N个地点和一个出发点(N<=10),给出全部地点两两之间的距离,问从出发点出发,走遍全部地点再回到出发点的最短距离是多 ...

  8. POJ 3311 Hie with the Pie 最短路+状压DP

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11243   Accepted: 5963 ...

  9. POJ 3311 Hie with the Pie (BFS+最短路+状态压缩)

    题意:类似于TSP问题,只是每个点可以走多次,求回到起点的最短距离(起点为点0). 分析:状态压缩,先预处理各点之间的最短路,然后sum[i][buff]表示在i点,状态为buff时所耗时...... ...

  10. [poj3311]Hie with the Pie(Floyd+状态压缩DP)

    题意:tsp问题,经过图中所有的点并回到原点的最短距离. 解题关键:floyd+状态压缩dp,注意floyd时k必须在最外层 转移方程:$dp[S][i] = \min (dp[S \wedge (1 ...

随机推荐

  1. Android SharedPreference 数据存储

    参考:http://www.cnblogs.com/friends-wf/p/4835818.html 应用开发过程中,数据存储几乎是肯定会遇到的问题,根据要存储的数据类型和数量,可以选择合适的存储方 ...

  2. jquery实现无外边框table

    jquery实现无外边框table 在需要设为无外边框的table上加上class noOutBorder <tableclass="noOutBorder"> < ...

  3. linux Grant 添加 MySql 用户

    Grant 添加 MySql 用户 2009-04-03 14:40 我安装的版本: mysql> select version();+------------+| version()   |+ ...

  4. 删除共享内存后key为0x00000000的问题

    一开始是 ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status root dest gyf ...

  5. 中局域网LAN中建立局域网可访问的类GitHub的服务器

    There are several ways to do this Host internal repositories like Gitlab (free software) or Stash. T ...

  6. 2015 CCPC D- Pick The Sticks(UESTC 1218) (01背包变形)

    http://acm.uestc.edu.cn/#/problem/show/1218 既然二维dp表示不了,就加一维表示是否在边界放置,放置一个,两个.有一个trick就是如果只放一根,那么多长都可 ...

  7. 高效Linux用户需要了解的命令行技能

    最近在Quora上看到一个问答题目,关于在高效率Linux用户节省时间Tips. 将该题目的回答进行学习总结,加上自己的一些经验,记录如下,方便自己和大家参考. 下面介绍的都是一些命令行工具,这些工具 ...

  8. Powerdesigner设置表结构对齐方式

  9. oc学习之路----QQ聊天界面

    用到的技术:自定义cell,通知机制,代理模式 transform 1.自定义cell(通过代码自定义cell) ①首先新建一个类继承UITableViewCell ②重写initWithStyle: ...

  10. 使用innobackupex备份mysql数据库

    1  因为使用perl脚本编写,安装前应先安装 yum install perl-Time-HiRes -y yum -y install perl-DBD-MySQL.x86_64 一起安装     ...