题目链接: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. linux shell 中"2>&1"含义

    脚本是:      nohup /mnt/Nand3/H2000G  >/dev/null  2>&1  &      对于& 1 更准确的说应该是文件描述符 1, ...

  2. tmux快捷键`

    Ctrl+b 激活控制台:此时以下按键生效 系统操作 ? 列出所有快捷键:按q返回 d 脱离当前会话:这样可以暂时返回Shell界面,输入tmux attach能够重新进入之前的会话 D 选择要脱离的 ...

  3. HW5.12

    public class Solution { public static void main(String[] args) { printChars('1', 'Z', 10); } public ...

  4. HW2.13

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  5. hdu3394--Railway(点的双连通分量)

    一个公园中有 n 个景点,景点之间通过无向的道路来连接,如果至少两个环公用一条路,路上的游客就会发生冲突:如果一条路不属于任何的环,这条路就没必要修 问,有多少路不必修,有多少路会发生冲突 每一个连通 ...

  6. 问题-[delphi2007、2010]无法二次启动,报EditorLineEnds.ttr被占用,进程一直有bds.exe?

    问题现象:delphi2007.2010无法二次启动,报EditorLineEnds.ttr被占用,而且进程中一直有bds.exe的进程? 问题原因:问题处理:方法一:可能是系统更新的东东造在的.KB ...

  7. RadHat搭建内网YUM源server

    前言:随着内网linuxserver越来越多,在每台server上安装软件.都要先把安装盘上传上去.在配置本地yum服务,即麻烦又费时.能够在内网的一台linuxserver上安装yum服务,然后其它 ...

  8. Oracle Outline总结

    一.基本概述 Oracle Outline,中文也称为存储大纲,是最早的基于提示来控制SQL运行计划的机制.也是9i以及之前版本号唯一能够用来稳定和控制SQL运行计划的工具. outline是一个hi ...

  9. android优化(json工具,message新建/传递,avtivity深入学习视频)

    1,在线json校验工具:www.bejson.com 2, 在handler中经常使用的 message的传递上,message.what使用静态量 . private static final i ...

  10. tcp_tw_reuse 与 net.ipv4.tcp_tw_recycle

    最近发现几个监控用的脚本在连接监控数据库的时候偶尔会连不上,报错: Couldn't connect to host:3306/tcp: IO::Socket::INET: connect: Cann ...