HDU 1010 Tempter of the Bone heuristic trim

Source: Internet
Author: User

The problem is that the test is trimmed.

Should be said to be more advanced applications.

Because of the use of heuristic (experience) pruning. Summarize the rules of thumb in this area, don't be easy. I say that this is also due to the fact that the application in the Advanced online report does not analyze too much too well to solve this problem, the plan gives also very slowly, only lost. From this a lot of people do not do this question.


Here I need to correct the online popular saying: Odd-even pruning method.

In fact, the use of odd-and-even pruning method is not too big to mention the speed, only to let the use of odd-even pruning off.

So the online said that the use of odd-even pruning, in fact, can not mention the speed of fast.

Reason:

Parity pruning can only be pruned once, not at the time of recursive pruning, because only to initialize the location to match the parity, then the random squares will be consistent with parity.

Therefore, in theory, it is not possible to raise speed. Of course I have experimented many times. Proving that parity pruning is not very useful at least for the subject.


The main pruning method should be one: the maximum number of spaces and the number of steps. That is, assume that the space number is born grids. And the need to walk the T-step, grids < T, can be judged as No.

And, of course, a second pruning: Assume that the current position to the target location requires at least steps steps. If you need to take a T-step, then steps > t, you can be judged No.

It just turns out that the first pruning method is only needed.

The second pruning is of little use, for the reason: there are very few recursive lattices. Calculating the distance difference does not improve how much speed.


If I use only one major pruning in the following recursive loops, it is enough, not over 100ms. Although not 0ms, but the speed is already fast enough.

0MS is expected to require further pruning. There are Daniel, please do not hesitate to enlighten me. It's time to delve into a * algorithm.

int sr = 0, sc = 0, dr = 0, DC = 0, N, m, grids, tsec;vector<string> maze;bool Escapemaze () {if (sr = = Dr && sc = = DC) {if (tsec = = 0) return True;return false;} if (grids < tsec) return false;if (tsec = = 0) return FALSE;MAZE[SR][SC] = ' $ '; grids--; Tsec--;if (sr+1 < (int) maze.size () && maze[sr+1][sc] = = '. ') {sr++;if (Escapemaze ()) return true;sr--;} if (sc+1 < (int) maze[0].size () && maze[sr][sc+1] = = '. ') {sc++;if (Escapemaze ()) return true;sc--;} if (sc > 0 && maze[sr][sc-1] = = '. ') {sc--;if (Escapemaze ()) return true;sc++;} if (sr > 0 && MAZE[SR-1][SC] = = '. ') {sr--;if (Escapemaze ()) return true;sr++;} MAZE[SR][SC] = '. '; grids++; Tsec++;return false;} int main () {while (scanf ("%d%d%d", &n, &m, &tsec) && n) {grids = n * m-1;maze.clear (); Maze.resize (n ); for (int i = 0; i < n; i++) {cin>>maze[i];for (int j = 0; J < m; J + +) {if (maze[i][j] = = ' S ') sr = i, sc = j; Don't forget this is ' S ' else if (maze[i][j] = = ' D ') Dr =I, DC = j, maze[i][j] = '. '; else if (maze[i][j] = = ' X ') grids--;}} int t = tsec-(ABS (DR-SR) + ABS (DC-SC)); if (T < 0 | | (T & 1) | | Grids < TSEC) puts ("no"), else if (Escapemaze ()) puts ("YES"), Else puts ("no");} return 0;}



Copyright notice: The author Jing Heart, King Space address: http://blog.csdn.net/kenden23/, only after the author agreed to reprint.

HDU 1010 Tempter of the Bone heuristic trim

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.