博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3311 Hie with the Pie (floyd+状压dp)
阅读量:6149 次
发布时间:2019-06-21

本文共 2412 字,大约阅读时间需要 8 分钟。

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 j via 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.

Sample Input

30 1 10 101 0 1 210 1 0 1010 2 10 00

Sample Output

8

Source

 
/*dp[i][j]表示在i个状态下最后到达j城市的最小时间*/#include
#include
#include
#define N (1<<10)+5#define M 15#define INF 0x3f3f3f3fusing namespace std;int dp[N][M],g[M][M],n;//dp[i][j]表示在第i个状态下最后到达j城市的最小时间,g[i][j]表示从i城市到达j城市的最小时间void floyd()//求出从i城市到j城市的最短路径(佛洛依德算法){ for(int k=0;k<=n;k++)//枚举中间点 for(int i=0;i<=n;i++)//枚举起点 for(int j=0;j<=n;j++)//枚举终点 g[i][j]=min(g[i][j],g[i][k]+g[k][j]);}int main(){ //freopen("in.txt", "r", stdin); while(scanf("%d",&n)!=EOF&&n) { //memset(dp,0,sizeof dp); //memset(g,INF,sizeof g); for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) scanf("%d",&g[i][j]); floyd();//求出从i到j的最短路径 int tol=(1<

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/5740387.html

你可能感兴趣的文章
检查磁盘利用率并且定期发送告警邮件
查看>>
MWeb 1.4 新功能介绍二:静态博客功能增强
查看>>
摄像机与绕任意轴旋转
查看>>
rsync 服务器配置过程
查看>>
预处理、const与sizeof相关面试题
查看>>
爬虫豆瓣top250项目-开发文档
查看>>
有趣的数学书籍
查看>>
teamviewer 卸载干净
查看>>
多线程设计模式
查看>>
解读自定义UICollectionViewLayout--感动了我自己
查看>>
SqlServer作业指定目标服务器
查看>>
User implements HttpSessionBindingListener
查看>>
eclipse的maven、Scala环境搭建
查看>>
架构师之路(一)- 什么是软件架构
查看>>
USACO 土地购买
查看>>
【原创】远景能源面试--一面
查看>>
B1010.一元多项式求导(25)
查看>>
10、程序员和编译器之间的关系
查看>>
前端学习之正则表达式
查看>>
配置 RAILS FOR JRUBY1.7.4
查看>>