Question Link
The question is very simple. Give a two-dimensional maze where the starting point is S, the ending point is t, and the other locations are lowercase letters A-Z. Ask what is the shortest path of a maximum of K letters, output letters. If there are multiple types of lettersMinimum Lexicographic Order.
Because most of CF is SPJ, I didn't notice the minimum Lexicographic Order. I thought it was a simple search with 26 letters and only K types. It was easy to think of State compression, but 2 ^ 26*50*50 is too big to open the array. When I saw k <= 4, I thought of enumerative letters and then searched for it. C () * 50*50. If I could accept it, I typed it and found that the minimum Lexicographic Order was required, after adjusting the search order, I handed in the 13th groups. After reading the data, I found that there was still a problem with the Lexicographic Order. The letters added during every step of the normal question were different, in this way, the minimum lexicographic path can be obtained in each step greedy, and the same letter will appear when this question is moved. In this way, the greedy policy behind this question is based on the previous steps, and it is too time-consuming, I am YY and adjust it several times, and I still lick it. Only then can I find that the Lexicographic Order is the key to this question ~~
After three or four hours, I couldn't help it, so I had to look at it.CodeAfter reading it, I found that this clear a * + brute-force search is definitely a brute-force search. It directly adds the location, path, character type, number of steps, and a brain into a structure, when searching, the Manhattan distance is used as the * function, and the number of evaluation steps is the smallest. Secondly, the path Lexicographic Order is the smallest and the map is used for hashing. It's so violent. Fortunately, a * doesn't feel like it's a dream. After I try it myself, A * is really awesome. After removing a *, it times out, after 30 ms, I felt that this a * was too cool here. The first time I saw a * with such a great effect, I put down this question.
Yesterday I thought about this question again. I felt something wrong. The A * function only adjusted the search order and found the solution faster. However, when there was no solution, the number of searches would not be reduced, the following data group is constructed:
50 50 4 Gbit/s have been found too many already exist. Why? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas? Why? zookeeper aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarxyzt
Haha, with this set of data, almost all the code in the first few clicks. At least two minutes, it seems that CF is also weak in data.
However, this is easy to solve. You only need to use a simple BFS in advance to determine whether a feasible solution exists. If no solution exists, it will be killed. If there is a solution, use a * to quickly find it, it is still a good solution.
Later I read watashi's code. Although his code is not fast, he ran more than 1 s, but the data above was generated in seconds, using different methods, after reading it carefully, I found that it was similar to my earliest thought. Enumerate every k letters and perform a brute-force search. He splits the search part and the search precursor part and writes them separately. Then, he knows a lot, then, sort the paths after the sort on the previous layer as the basis for the next layer of sorting. In this way, the minimum Lexicographic Order is obtained, then, we can take the path obtained from each enumeration to a minimum value.
The code will not be pasted ..