algorithm - Use dynamic programming to find a polygonal chain that best fits a set of data points -


The question is said as the following:

Looking at the sequence of digits p_1 = ( x_1, y_1), ..., p_n = (x_n, y_n) and by it the x-coordinate (i.e. x_1 & lt; x_2 & lt; ... & lt; x_n) from left to right and 1 and n Between a number q we want that P1 to PN With the K-edges from the PN, which goes from left to right, want to reduce the sum of the vertical distance of the series points . O (n ^ 3) Design a dynamic programming algorithm to solve the problem in time. The method to calculate the sum of the vertical distance of p_a + 1 points. . , p_ap_b for line through p_b_ 1 is given by F (A, B).

Enter image details here

Because of testing for me It is difficult to write an example, so I do not know if my answer is correct or not.

The answer is as follows:

First of all, I define polygon chain interval on the PE of [i, j] = PI, the minimum sum of the vertical distance. And the answer should be C [N, K].

For the base case, I define c [i, 0] = 0 and c [i, j] = + infinity when j & gt; = I.

For the recursive formula, I see C [i, j] = minimum (1

l; i) {c, p, j-1] + f (p, i)} < / P>

Is anything wrong in my answer? Thank you.

example where the point is better to use P for a series ( set of p_i ).

  P = {(0, 0), (1, 1), (3, 1), (4, 0)} k = 2 + (2,2) * (1, 1) * (3,1) * (0,0) * (4,0)   

2 Points for a series with numbers in P Both have f (1,4) = 2/3 . (2, 2) returns the series point as f (1,4) = 0 .

The solution to the problem without any restriction, P , is difficult to describe in a DP manner. It looks like a problem of regression with many obstacles.

I think that in this problem, it is expected to be from P for series points.

Update

is similar to the Lower Records original, such as j_random_hacker has been mentioned.

I think it's better to define a slightly different function. Define the minimum cost of the chain between p_a and p_b with the e edges C (A, B, E) . The answer to our problem is C (1, n, k) .

  c (a, b, 1) = f (a, b) c (a, a + i, i) = 0 c (a, b, k) = inf, k & Gt; B-A   

There are different recomputations that can be used. This is the 'length' of the last edge:

  c (a, b, k + 1) = minutes (c (a, c, k) + c (i, b, 1) ), I for a + k, b-1    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -