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

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

Hie with the Pie
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 5896   Accepted: 3180

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,现在有n个地方(标号1到n)要从标号为0的地方出去,经过所有的地方之后回来,求最短的时间,输入(n+1)*(n+1)的矩阵表示每两点之间到达所需要的时间。

思路:用dp[i][j]表示状态i下以j结尾的最短时间。由于不知道每两个点之间到底怎么走时间最短,用floyd求一下最短路程,然后进行dp。

#include 
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;int dp[1<<11][11];///dp[i][j]表示i状态下以j结尾的最短时间int tu[15][15];int n;const int INF=99999999;void floyd()///floyd求两点间的最短路{ for(int k=0; k

转载于:https://www.cnblogs.com/martinue/p/5490433.html

你可能感兴趣的文章
最短路之dijkstra算法
查看>>
SHDP--Working With HBase (二)之HBase JDBC驱动Phoenix与SpringJDBCTemplate的集成
查看>>
Lua语法基础(一)
查看>>
.Net Core2.*学习手册
查看>>
实验一、命令解释程序的编写实验
查看>>
2018年11月14日 学习字符串用法2
查看>>
2019年5月26日 re模块2
查看>>
Mac显示器不亮
查看>>
luogu P2312 解方程
查看>>
Cordova开发速记
查看>>
Chrome开发工具
查看>>
MySQL 的 RowNum 实现
查看>>
网络工程师应该掌握的44个路由器问题
查看>>
windows 控制台下运行cl命令
查看>>
(七十八)使用第三方框架INTULocationManager实现定位
查看>>
LeetCode问题:搜索插入位置
查看>>
JVM基础学习之基本概念、可见性与同步
查看>>
UML入门
查看>>
CodeForces - 524F And Yet Another Bracket Sequence
查看>>
python学习笔记-day10-2【多进程,多线程】
查看>>