'Y' is your current position (there is one and only one Y in the given map).
'.' is a normal grid. It costs you 1 MV to enter in this gird.
'T' is a tree. It costs you 2 MV to enter in this gird.
'R' is a river. It costs you 3 MV to enter in this gird.
'#' is an obstacle. You can never enter in this gird.
'E's are your enemies. You cannot move across your enemy, because once you enter the grids which are adjacent with 'E', you will lose all your MV. Here “adjacent” means two grids share a common edge.
'P's are your partners. You can move across your partner, but you cannot stay in the same grid with him final, because there can only be one person in one grid.You can assume the Ps must stand on '.' . so ,it also costs you 1 MV to enter this grid.
给出一张图,和总共的步数。
然后输出走过的图,能走的地方都用*标记。
A了10来个小时,第一次用DFS做,标记visit[][],然后回溯,但是直接TLE。因为visit[][]标记的只是一次步数全部走完路径,走完之后就都回溯了,这样就造成很多重复的步骤。
第二次换了BFS,但是没有用标记数组,直接爆栈了T_T。
第三次还是BFS,但是加了个visit[][]数组来储存步数,在搜索的过程中,每次走到这一步,都更新visit[][]的步数,使得走到坐标(x,y)的剩余步数最大。
[cpp]
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include