题意/Description

    The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait for 1 or more (up to 10) orders to be processed before he starts any deliveries. Needless to say, he would like to take the shortest route in delivering these goodies and returning to the pizzeria, even if it means passing the same location(s) or the pizzeria more than once on the way. He has commissioned you to write a program to help him.


读入/Input:

    Input will consist of multiple test cases. The first line will contain a single integer n indicating the number of orders to deliver, where 1 ≤ n ≤ 10. After this will be n + 1 lines each containing n + 1 integers indicating the times to travel between the pizzeria (numbered 0) and the n locations (numbers 1 to n). The jth value on the ith line indicates the time to go directly from location i to location j without visiting any other locations along the way. Note that there may be quicker ways to go from i to jvia other locations, due to different speed limits, traffic lights, etc. Also, the time values may not be symmetric, i.e., the time to go directly from location i to j may not be the same as the time to go directly from location j to i. An input value of n = 0 will terminate input.


输出/Output

    For each test case, you should output a single number indicating the minimum time to deliver all of the pizzas and return to the pizzeria.


题解/solution

 这题听一个姓刘的说,要用folyd+状态压缩DP,听起来好恐怖。给出DP式子:

    f[k,i]:=f[k xor (1 shl (i-1)),j]+a[j,i]; (k xor (1 shl (i-1))<>0),((1 shl (j-1))<>0)

  乍一看真的好恐怖。

  解释一下:DP式子指:在没经过城市I的状态中,寻找合适的中间点J使得距离更短,和FLOYD一样。

条件是指:状态S中已经过城市i  ,枚举不是城市I的其他城市。

  然后自己敲吧。


代码/Code

(部分程序)

procedure main;
varj,i,k:longint;
beginfillchar(f,sizeof(f),$7f);f[0,1]:=0;for k:=0 to 1 shl n-1 dobeginfor i:=1 to n dobeginif k=1 shl (i-1) then f[k,i]:=a[0,i];if (k and (1 shl (i-1)))<>0 thenbeginfor j:=1 to n doif (k xor (1 shl (i-1))<>0) and ((1 shl (j-1))<>0) thenif f[k xor (1 shl (i-1)),j]+a[j,i]<f[k,i] thenf[k,i]:=f[k xor (1 shl (i-1)),j]+a[j,i];end;end;end;
end;procedure print;
vari:longint;
beginans:=maxlongint;for i:=1 to n doif ans>f[1 shl n-1,i]+a[i,0] then ans:=f[1 shl n-1,i]+a[i,0];writeln(ans);
end;

PKU 3311 Hie with the Pie 最短路 folyd相关推荐

  1. [POJ 3311] Hie with the Pie

    这是状压DP中常见的一类问题(TSP问题)(废话) 题目大意: 给你一个n+1个点的有向完全图,现在要你从0号节点出发走过1-n号点至少一次,再返回0号点的最少时间,1<=n<=10 题意 ...

  2. POJ 3311 Hie with the Pie (flyod + DFS枚举)

    先用floyd算法求出 2点间的最短距离,然后再用深搜枚举即可. #include<cstdio> #include<cstring> #include<iostream ...

  3. POJ - 3311 Hie with the Pie

    题目: The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unf ...

  4. Hie with the Pie(Floyd 状压DP)

    POJ 3311 Hie with the Pie 题目大意 一个披萨店要请司机来送披萨,这家店最多接受10个订单,由于预算的问题,只能雇佣一名司机,要求用最短的时间,从披萨店出发送完最后再回到披萨店 ...

  5. 【POJ 3311】Hie with the Pie(状压DP)

    Hie with the Pie 题目链接:POJ 3311 题目大意 给你 n+1 个点,其中 0 号点是特殊点. 然后两个点之间都有路径可以走. 然后你要从特殊点出发走过所有点回到特殊点,问你最短 ...

  6. Hie with the Pie(poj3311)

    题目链接:http://poj.org/problem?id=3311 学习博客:https://blog.csdn.net/u013480600/article/details/19692985 H ...

  7. Hie with the Pie(旅行商问题)

    Hie with the Pie 题目链接 Description The Pizazz Pizzeria prides itself in delivering pizzas to its cust ...

  8. Hie with the Pie

    Hie with the Pie poj-3311 题目大意:n+1个点,伪旅行商问题. 注释:n<=10. 想法:咳咳,第一道状压dp,下面我来介绍一下状压dp. 所谓dp,就是动态性决策规划 ...

  9. 【POJ P3311】【状压DP】Hie with the Pie

    Hie with the Pie 题目 解题思路 Code POJ P3311 Hie with the Pie 题目 Description The Pizazz Pizzeria prides i ...

最新文章

  1. xebium周末启动_我如何在周末建立和启动聊天机器人
  2. 如何只在IE上加载CSS样式表
  3. C#编程规范--控件命名篇[转]
  4. RL之DQN:基于TF训练DQN模型玩“打砖块”游戏
  5. android 线程太多,应用程序可能在其主线程上做了太多的工作。
  6. streaming接mysql数据库_[Spark streaming举例]-- 实时统计并且存储到mysql数据库中
  7. 转一篇好文,虽然争议颇多,还是觉得有必要转一下看看 来自博客园
  8. 大数据可视化大屏设计经验,教给你!
  9. iPhone4S安装Linux系统,别失望太早 iPhone 4S其实就是iPhone 5
  10. web开发-引用Google font library-学习笔记四
  11. 华为USB线刷工具的使用
  12. python樱花树代码_Python绘图案例:2020年新年画一棵樱花树(源代码)
  13. echarts绘制地理坐标/地图
  14. Mac如何安装第三方新字体?Mac字体安装图文教程
  15. 如何拿下头条号原创标?这里有份6000字的指南
  16. 滚动轴承故障检测与诊断(一)
  17. 【PyTorch教程】P27、28、29 完整的模型套路
  18. 1580_AURIX_TC275_SMU模块初步
  19. Lottie- 让Android动画实现更简单
  20. scrapy框架中实现登录人人网(一)(最新登录方式)

热门文章

  1. 浅谈rpc(远程过程调用)
  2. 这东西有什么好吃的,我也就吃了二十多碗吧 | 钛空舱
  3. 北京航空航天计算机学院陈小武,最新2015年北京航空航天大学计算机应用技术考博考试科目.doc...
  4. 科普 | 什么是贴片电阻?
  5. Python抢票项目源码
  6. 安卓OpenGL ES——透视投影
  7. 商业企业的供应链管理模型
  8. 【python3】基于随机森林的气温预测
  9. Oracle EBS PA模块费用分摊与转资摘记
  10. C#:如何用VS开启人生中第一个Windows窗体应用程序(Winform)?