Summary: BFS

Source: Internet
Author: User

Summary: we can search down at the same depth when the initial state is about to reach the termination state, which covers a wider range and is very useful when the depth of the solution is small.

Tips and notes:

BFS has many tips. Let me list them one by one:

Note:: When saving BFS status, you must try to reduce the status and store only valid information for BFs, instead of storing the entire figure (Qaq and noip are suspended in this way. It was too weak at the time ..)

Hash weight: In some BFS questions, where the range of all elements is small (you can also map them yourself), let's assume that there are K yuan, we can consider using hash based on the power of the base number in K-base, for example, [wikioi] 1004 sizgame, [bzoj] 1054: [haoi2008] mobile toys (BFS + hash ),

Array Weighting: In some cases, such as pure BFS or direction restrictions, you can open multi-dimensional arrays to record the access status. For example: [wikioi] Ralf, who escaped in 1026 (heavy direction), [bzoj] 1616: [usac2008 Mar] cow, travelling, wandering dairy cows (DP/-BFS) (strong decision), [bzoj] 1644: [usac2007 Oct] obstacle course obstacle Training Course (BFS) (heavy direction Judgment ),

Obstacle distance: When you see a picture of the maximum number of obstacles from the start point to the end point to give you BFs, you can think against it. We think the minimum number of obstacles to be crossed from this point to the end point, then, use K to determine whether it is legal, for example:

Multiple Constraints: When the number of constraints increases, we can consider maintaining multiple types of information when BFS is transferred, and then making decisions based on the question, for example: [bzoj] 1632: [usaco2007 Feb] Lilypad pond (BFS)

Circle Constraint: When BFS asks us to take the shortest distance around a specified shape (with a connected shape), we can take a Ray from the point of the Shape boundary, then, the BFS is maintained after the BFS, that is, it does not pass through the ray, or it does not pass through the ray to the need to pass through the ray. That is to say, we need to maintain the latter when we make a round trip, for example, [bzoj] 1656: [usaco 2006 Jan] The Grove tree (BFS + Special tips)

Bidirectional search: When you encounter a minimum number of moving steps from the initial status to the target status, we can perform BFS in both the initial and target statuses, then you can determine whether the intersection exists. I wrote a question a long time ago. I don't know which question ..

Summary: BFS

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.