Differential constraint explanation

Source: Internet
Author: User

Always do not know what type of differential constraint is the problem, and recently in writing the shortest way to see the next, the original is to give some form as x-y<=b inequality constraints, asked whether you meet the problem of the solution

It's amazing how this kind of problem can be converted into the shortest path problem in graph theory, which starts with a detailed introduction

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

From the question we can be informed that this has to map, by the problem b-a<=k1,c-b<=k2, c-a<=k1+k2, so compare k1+k2 and K3 size, find the smallest is the maximum value of c-a

According to the above solution, we may guess that the solution process is actually seeking the shortest path from a to C, yes .... The simple point is that from a to C along a path after the ownership value and K to find out is a c-a<=k

Generalized inequality constraints, in this case, 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.

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

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

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

Note the point:

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

If the minimum value is required, it becomes the standard form of x-y>=k, then a K-side from Y to X is created, and the longest path can be obtained.

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


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.