HDU-3502-Huson's Adventure Island(BFS+如压力DP)

简介:
Problem Description
A few days ago, Tom was tired of all the PC-games, so he went back to some old FC-games. "Hudson's Adventure Island" was his favorite which he had played thousands of times. But to his disappointed, the more he played, the more he lost. Tom soon gave up the game. 



Now, he invents an easier game on the base of “Hudson's Adventure Island”. He wants to know whether the new game is easy enough. So he came to you for help. 
To simplify the problem, you can assume there is matrix-map contains m(0 < m < 256) rows, n(0 < n < 256) columns, an entrance on the top-left corner (0, 0), an exit on the bottom-right corner (m-1, n-1). Each entry of the matrix contains a integer k.The range of k is defined below:
a)k = 0,it is a free space one can go through.
b)k = -1,it is an obstacle one can’t go through.
c)0 < k < 10000,it is a fruit one can go through and gain k points of energy.
d)k >= 0 at the entrance point and the end point.
At the begin, the hero has 0 points of energy and he can go four directions (up, down, left, right). Each move he makes cost 1 point of energy. No energy no move. If he can’t make a move or get to the exit, he loses the game. The number of fruit is 17 at most.
 

Input
The input consists of multiple test cases. Each test case starts with two positive integers m, n. Then follows m lines, each line contain n integers.
 

Output
For each case, if the hero can get the exit, find and print the maximum points of energy he left. Or print “you loss!”
 

Sample Input
 
 
4 4 8 0 0 0 -1 -1 -1 0 -1 -1 -1 0 0 6 0 0 3 3 4 0 0 0 0 0 0 0 0 4 4 5 0 0 0 0 -1 -1 0 0 -1 -1 0 0 0 0 0
 

Sample Output
 
 
4 0 you loss!
Hint
The hero can pass the exit. When he gets the exit point, he can choose to get out to finish the game or move on to gain more points of energy.
 

Author
imems
 

Source


思路:先用BFS 求出各个水果和终点之间的距离,再用状态压缩DP求解。


 

}






本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5033639.html,如需转载请自行联系原作者


相关文章
|
8月前
|
存储 容器
华为机试HJ41:称砝码(深度优先遍历dfs-Depth First Search)
华为机试HJ41:称砝码(深度优先遍历dfs-Depth First Search)
|
机器学习/深度学习 人工智能
51nod 1055 最长等差数列 (dp好题)
51nod 1055 最长等差数列 (dp好题)
33 0
|
人工智能 Java
HDU-敌兵布阵(线段树 || 树状数组)
HDU-敌兵布阵(线段树 || 树状数组)
70 0
codeforces118——D. Caesar‘s Legions(DP)
codeforces118——D. Caesar‘s Legions(DP)
67 0
codeforces118——D. Caesar‘s Legions(DP)
|
机器学习/深度学习
HDU2376——Average distance(思维+树形DP)
HDU2376——Average distance(思维+树形DP)
71 0
POJ-1475,Pushing Boxes(双BFS)
POJ-1475,Pushing Boxes(双BFS)
CodeForces 377A-Maze(DFS找连通块)
CodeForces 377A-Maze(DFS找连通块)
CodeForces 377A-Maze(DFS找连通块)
|
机器学习/深度学习
POJ-1321,棋盘问题(DFS)
POJ-1321,棋盘问题(DFS)
HDU-3635,Dragon Balls(有点难度的并查集。。。)
HDU-3635,Dragon Balls(有点难度的并查集。。。)
|
机器学习/深度学习 算法
【刷穿 LeetCode】求「连通图经过所有点的最短路径」的三种方式 :「BFS」&「Floyd + 状压 DP」 &「AStar 算法」
【刷穿 LeetCode】求「连通图经过所有点的最短路径」的三种方式 :「BFS」&「Floyd + 状压 DP」 &「AStar 算法」