Hie with the Pie POJ - 3311】的更多相关文章

Hie with the Pie POJ - 3311 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 1…
昨天想练习一下状态压缩,百度搜索看到有博客讨论POJ 3311,一看就是简单的旅行商问题,于是快速上手写了状态压缩,死活样例都没过... 画图模拟一遍原来多个城市可以重复走,然后就放弃思考了... 刚刚把这个无聊的问题解决了,简单的Floyd+状压. 所谓Floyd算法,我在暑训的博客里提过,复杂度O(n3),但当时数据量太大不适合使用,这里刚好派上了用场. #include<cstdio> #include<iostream> #include<cstring> #i…
题目链接:https://cn.vjudge.net/contest/276236#problem/C 题目大意: 给你一个有n+1(1<=n<=10)个点的有向完全图,用矩阵的形式给出任意两个不同点之间的距离.(其中从i到j的距离不一定等于从j到i的距离)现在要你求出从0号点出发,走过1到n号点至少一次,然后再回到0号点所花的最小时间. 输入:包含多组实例.每个实例第一个为n,然后是n+1行矩阵,每行矩阵有n+1个数字,第i行第j个数字表示从i-1到j-1号点的距离.当输入n=0时表示输入结…
floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4013   Accepted: 2132 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fas…
Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4671   Accepted: 2471 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can affo…
Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4491   Accepted: 2376 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can affo…
Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11243   Accepted: 5963 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can aff…
题目链接:http://poj.org/problem?id=3311 学习博客:https://blog.csdn.net/u013480600/article/details/19692985 Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9954   Accepted: 5368 Description The Pizazz Pizzeria prides itself in de…
题目链接:http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:12225   Accepted: 6441 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortuna…
Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6436   Accepted: 3470 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can affo…
Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3160   Accepted: 1613 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can affo…
题意: 给i到j花费的地图 1到n编号   一个人要从1遍历n个城市后回到1 求最小的花费(可以重复走) 分析 http://www.cnblogs.com/Empress/p/4039240.html TSP 因为可以重复走 所以先floyd一下求最短路 #include <cstdio> #include <cstdlib> #include <cstring> #include <climits> #include <cctype> #in…
Hie with the Pie poj-3311 题目大意:n+1个点,伪旅行商问题. 注释:n<=10. 想法:咳咳,第一道状压dp,下面我来介绍一下状压dp. 所谓dp,就是动态性决策规划,通过上一时刻或上几时刻的状态来更新当前状态并且无后效性.而状压dp就是将之前的状态通过二进制表现出来.几个例子.有五个格子_ _ _ _ _.上面可以放棋子或者不放.我们将放棋子的格子标注为1,不放棋子的格子标注为0.那么,我们就可以用一个二进制数来表达出人任何一个的完整状态而不是片面的,这就是状压dp…
poj  3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以重复走,先用floyd预处理每个点两两之间的最短距离,然后用状态压缩DP求出走完所有点后回到原点的最短距离,用一个二进制数表示城市是否走过. 状态表示:dp[i][j]表示到达j点状态为i的最短距离 状态转移方程:dp[i][j]=min(dp[i][j],dp[j'][k]+dis[k][j]),…
C - Hie with the Pie Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Appoint description:  System Crawler  (2014-05-15) Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as…
Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5205   Accepted: 2790 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can affo…
题目链接: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][…
题目链接:http://poj.org/problem?id=3311 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 fo…
主题连接:  id=3311">http://poj.org/problem?id=3311 题目大意:有n+1个点,给出点0~n的每两个点之间的距离,求这个图上TSP问题的最小解 思路:用二进制数来表示訪问过的城市集合.f[{S}][j]=已经訪问过的城市集合为S,訪问了j个城市.所需的最少花费. 这里提一下二进制数表示集合的方法(这里最好还是设集合中最多有n个元素): 假设集合S中最多会出现n个元素,则用长度为n的二进制数来表示集合S,每一位代表一个元素.该位为0表示该元素在集合S…
链接:http://poj.org/problem?id=3311 题意:有N个地点和一个出发点(N<=10),给出全部地点两两之间的距离,问从出发点出发,走遍全部地点再回到出发点的最短距离是多少. 思路:首先用floyd找到全部点之间的最短路.然后用状态压缩,dp数组一定是二维的,假设是一维的话不能保证dp[i]->dp[j]一定是最短的.由于dp[i]记录的"当前位置"不一定是能使dp[j]最小的当前位置.所以dp[i][j]中,i表示的二进制下的当前已经经过的状态,j…
题目链接:http://poj.org/problem?id=3311 题意: 你在0号点(pizza店),要往1到n号节点送pizza. 每个节点可以重复经过. 给你一个(n+1)*(n+1)的邻接矩阵,表示各点之间距离. 问你送完所有pizza再返回店里的最短路程. 题解: 与传统TSP相比,唯一变化的条件是每个节点可以经过多次. 所以也就是转移的时候不用再判断要去的节点j是否去过. 先floyd预处理出两点之间最短路.然后把(!((state>>j)&1))去掉,套TSP模板就好…
dp[i][j][k] i代表此层用的状态序号 j上一层用的状态序号 k是层数&1(滚动数组) 标准流程 先预处理出所有合法数据存在status里 然后独立处理第一层 然后根据前一层的max推下一层 由于最多只有60多种状态 所以这其实就是个大暴力 其实还不慢 关于为什么要反义输入地图 因为我懒得写一个地图匹配状态函数了 所以直接让地图反义匹配状态 应该算是比较简单的状压DP 然而我还是写残了WA了两次orz #include <iostream> #include <strin…
题是看了这位的博客之后理解的,只不过我是又加了点简单的注释. 链接:http://blog.csdn.net/chinaczy/article/details/5890768 我还加了一些注释代码,对于新手的我,看起来可能更方便些吧,顺便说下快捷键 先选中要操作的行,ctrl+shift+c 是注释 ctrl+shift+x是解注释(cb的快捷键) /* Floyd + 状态压缩DP 题意是有N个城市(1~N)和一个PIZZA店(0),要求一条回路,从0出发,又回到0,而且距离最短 也就是TSP…
题意:披萨店给n个地方送披萨,已知各地方(包括披萨店)之间花费的时间,求送完所有地方并回到店花费的最小时间 分析:状态好确定dp[i][j],i中1表示地方已送过,否则为0,j为当前状态最后一个送过的地方,注意怎么走才算最小时间,当然是走最短路,点很少由floyd求出各点最短路 求回到店的最小时间,从店出发(状态为1). #include <map> #include <set> #include <list> #include <cmath> #inclu…
Description The Pizazz Pizzeria prides itself or more (up to ) 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 mea…
题意:类似于TSP问题,只是每个点可以走多次,求回到起点的最短距离(起点为点0). 分析:状态压缩,先预处理各点之间的最短路,然后sum[i][buff]表示在i点,状态为buff时所耗时....... 所以把10 * 1024 种状态来一遍,取sum[0][(1<<n)-1]的最小值 只是把状态压缩DP改成bfs+状态压缩了 #include <cstdio> #include <iostream> #include <cstring> #include…
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…
下面是别人的解题报告链接: http://blog.csdn.net/accry/article/details/6607703 下面是我的代码,我觉得链接中的代码有一点小问题,也许是我想错了吧. #include <cstdio> #define min(a,b) (a) < (b) ? (a) : (b); #define INF 100000000 ][]; ][]; void init(int n) { ; i<=n; ++i) ; j<=n; ++j) scanf(…
题目链接 题意 给定一个\(N\)个点的完全图(有向图),求从原点出发,经过所有点再回到原点的最短路径长度(可重复经过中途点). 思路 因为可多次经过同一个点,所以可用floyd先预处理出每两个点之间的最短路径. 接下来就是状压dp的部分. 将已经经过的点的状态用\(state\)表示, 则\(dp[state][k]\)表示当前到达点\(k\)后状态为\(state\)时的最短路径长度. \[ans=min_{i=1}^{n}(dp[(1<<n)-1][i]+dis[i][0])\] 可用记…
题意: 每个点都可以走多次的TSP问题:有n个点(n<=11),从点1出发,经过其他所有点至少1次,并回到原点1,使得路程最短是多少? 思路: 同HDU 5418 VICTOR AND WORLD (可重复走的TSP问题,状压DP)这道题几乎一模一样. //#include <bits/stdc++.h> #include <iostream> #include <cstdio> #include <cstring> #include <cmat…