博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
状态压缩 DP
阅读量:4307 次
发布时间:2019-06-06

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

D - Hie with the Pie

Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

 

Input

 

Output

 

Sample Input

 

Sample Output

 

Hint

 

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

 

题意:

一个人从起点出发去n个地方送货,最后回到起点,给出每两个点之间的距离计算最短路程。

代码:

1 /* 2 dp[i][j]表示状态i时到达j点的时间,dp[i][j]=min(dp[i][j],dp[h][k]+d[k][j]),h表示的状态中没有j点 3 d[k][j]表示k点到j点的距离,由于是求最短要用一个flody算法算出最短距离 4 */ 5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 using namespace std;16 int n;17 int d[11][11];18 int dp[1<<11][11];19 int min(int x,int y)20 {21 return x
d[i][k]+d[k][j])39 d[i][j]=d[i][k]+d[k][j];40 }41 for(int i=0;i<(1<

 

转载于:https://www.cnblogs.com/--ZHIYUAN/p/5743840.html

你可能感兴趣的文章
FFmpeg 新旧版本编码 API 的区别
查看>>
RecyclerView 源码深入解析——绘制流程、缓存机制、动画等
查看>>
Android 面试题整理总结(一)Java 基础
查看>>
Android 面试题整理总结(二)Java 集合
查看>>
学习笔记_vnpy实战培训day02
查看>>
学习笔记_vnpy实战培训day03
查看>>
VNPY- VnTrader基本使用
查看>>
VNPY - CTA策略模块策略开发
查看>>
VNPY - 事件引擎
查看>>
MongoDB基本语法和操作入门
查看>>
学习笔记_vnpy实战培训day04_作业
查看>>
OCO订单(委托)
查看>>
学习笔记_vnpy实战培训day06
查看>>
回测引擎代码分析流程图
查看>>
Excel 如何制作时间轴
查看>>
股票网格交易策略
查看>>
matplotlib绘图跳过时间段的处理方案
查看>>
vnpy学习_04回测评价指标的缺陷
查看>>
ubuntu终端一次多条命令方法和区别
查看>>
python之偏函数
查看>>