Difference constraint system personal understanding, constraint personal understanding

Source: Internet
Author: User

Difference constraint system personal understanding, constraint personal understanding

 

Today, we are exposed to a mysterious thing:

Difference Constraint

Personal Understanding: The difference constraint is to give some restrictions to find the optimal solution that meets the conditions, or determine whether the conditions are true.

 

Practices/ideas:

1. First, write the corresponding inequality based on the conditions of the question.

2. Convert the inequality into a-B <= c

3. Create an edge with a weight of c, pointing from B to

4. Link an edge from 0 to another vertex with the right of 1

5. Run the deep search SPFA to check whether the answer is updated.

 

After this is done, the shortest path is obtained! The maximum value that meets the condition is obtained!

 

 

Of course, you can follow the opposite idea above,

The method and result are the opposite of the above, but both can be AC!

 

 

There must be a lot of doubts here. I will explain it based on my understanding.

1. Why do we need to build an edge from B to a with the weight of c?

Because a-B <= c, the edge weight between B and a is c, and the answer is

2. Why is the shortest path not the longest path?

Because every time we create the largest edge weight, we need to obtain the value that satisfies all the inequalities.

Then, when this value is the smallest value in all inequalities, the conditions can be met,

So we need the shortest path.

3. Why does SPFA need to perform deep search instead of wide search?

Because deep search is easy to judge negative loops!

4. Why do we need to build an edge from 0 to all vertices?

Personal feeling: to facilitate the updating of answers

But it may be incorrect. Please wait and ask your teacher...

 

We recommend several good articles:

Http://972169909-qq-com.iteye.com/blog/1185527

Http://www.cppblog.com/menjitianya/archive/2015/11/19/212292.html

 

Related Article

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.