题目链接:http://lightoj.com/volume_showproblem.php?problem=1057 题目大意:在二维矩阵中,给你一个起点和至多15个的目标点.要你求出从起点出发经过完所有的点后回到起点的最短路径值.每个点一步可以向 八个方向走. 算法思路:一看就觉得是tsp,用状态压缩.而任意两点的距离就是相应横纵坐标差的较大值.具体看代码. 代码: #include<cstdio> #include<cstring> #include<iostream&…
这道题可以想到几点: 整个行程可以看作一次次的行走,每次行走都是用最短的路程从某一非空点到达另外一非空点: 两点间最少的步数是二者x和y坐标差的最大值: 返回原点这个过程,肯定是取完最后一个黄金后直接用最少的步数从这儿出发回到原点. 然后就是状压DP了: dp[u][S]:经过非空点集S后到达u点最少的步数 转移就枚举从哪儿到达u点的. #include<cstdio> #include<cstring> #include<algorithm> using namesp…
1057 - Collecting Gold   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Finally you found the city of Gold. As you are fond of gold, you start collecting them. But there are so much gold that you are getting tired collecti…
题目大意: 给你一个矩阵,'x'是你的起始位置, 'g'是宝藏的位置,问最少多少步可以把所有的宝藏取完,并且最后返回起始位置. 注意:没有宝藏的时候输出 0   ==================================================================================== #include<cstdio> #include<cstring> #include<iostream> #include<algor…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1057 题解:看似有点下记忆话搜索但是由于他是能走8个方向的也就是说两点的距离其实就是最大的x轴或y轴的差.然后只有15个藏金点状压一下加dfs就行了. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #define inf 0X3f3f3f…
原题链接在这里:https://leetcode.com/problems/path-with-maximum-gold/ 题目: In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can colle…
题目如下: In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every time you are located in a cel…
Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 5090   Accepted: 2529 Case Time Limit: 2000MS   Special Judge Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stuff, he collect…
题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一个地方可重复访问多次. 经典的状压dp,因为每次送外卖不超过10个地方,可以压缩. 由于题中明确说了两个城市间的直接可达路径(即不经过其它城市结点)不一定是最短路径,所以需要借助floyd首先求出任意两个城市间的最短距离. 然后,在此基础上来求出遍历各个城市后回到出发点的最短路径的距离,即求解TSP…
题目描述 Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stuff, he collects software bugs. When Ivan gets a new program, he classifies all possible bugs into n categories. Each day he discovers exactly one…