A detailed description of the differential constraint system

Source: Internet
Author: User

This article transferred from: http://www.cnblogs.com/void/archive/2011/08/26/2153928.html

Always do not know what type of differential constraint is the problem, and recently in writing the shortest way to look at the next, the original is to give some form as x-y<=b inequality constraints, asked if you are satisfied with the solution of the problem!

The magic is that this kind of problem can be converted into the shortest path problem in graph theory, the following begins in detail:

(1) For example, given three inequalities, B-A<=K1,C-B<=K2,C-A<=K3, if the maximum value of c-a is required, we can convert a,b,c to three points, K1,k2,k3 is the right side,

By the question we can know, this has to the graph, by the question B-a<=k1,c-b<=k2, obtains c-a<=k1+k2, therefore compares K1+K2 and K3 the size, the smallest is the c-a maximum value.

According to the above solution, we may guess that the solution process is actually seeking the shortest path from a to C, yes .... Simply said from a to c along a path after the ownership value and K is a generalization of c-a<=k inequality constraints, since this, the satisfaction of the topic is certainly the smallest k, that is, from a to c the shortest distance ...

After understanding here, want to do the problem is still more difficult, because the problem needs to be deformed, not simple calculation.

(1) First Take poj3159 as an example, this is relatively simple, is to give two points of the maximum difference, and then let you ask 1 to n the maximum difference, directly after the map with Bellman or SPFA can be passed.

(2) A little difficult is poj1364, because he gave the inequality is not x-y<=k form, sometimes greater than the number, so that we need to deform a bit, and give or >,< not equal to, are deformed

(3) Then there is poj1201, he asked for the longest distance, it is necessary to transform the form into a standard form of x-y>=k

(deform) Note:

1. If the maximum value is required to find a way to change each inequality into a standard x-y<=k form, and then create an edge from Y to x weights of K, it becomes time to pay attention to x-y<k = x-y<=k-1.

2. If the minimum value is required, change to the standard form of x-y>=k, then create a K-side from Y to X to find the longest path.

3. If the weight is positive, use Dj,spfa,bellman can, if the negative can not use the DJ, and need to determine whether there is a negative ring, some words do not exist.

A detailed description of the differential constraint system

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.