"ORZ5" 2014.08.09 Training Summary

Source: Internet
Author: User
Tags abs min

Today is a nice day!

These days do a few sets of questions now come to one by one summary.

ORZ5 Vijos Demo Game

As a result of this series of previous games, there are some rules resulting in this score is relatively high.

Match score 100+100+100+0.

T1 Max Pairing

Title: Give 2 sequence A={a[1],a[2],...,a[n]},b={b[1],b[2],...,b[n]}, from a, B each selected k elements for one by one pairs (can not be in the order of the original in the sequence), and make all pairs of element difference of the absolute value of the maximum.
For example, select A[p[1]],a[p[2]],......,a[p[k]] and B[q[1]],b[q[2]],......,b[q[k]], where the p sequence of element 22 is not the same, the Q sequence of element 22 is not the same, then the answer is |a[p[1]]-b[q[1]]| +|a[p[2]]-b[q[2]]|+ ... +|a[p[k]]-b[q[k]]|, the task now is to maximize the answer.

and Noip difficulty as the first question is generally not too difficult to pay attention to a little bit do not drop the pit just fine.

Analysis, easy to pass each best match must be the maximum minimum, so as long as a, b order from the maximum minimum to match.

T2 Travel

Title: Today is a sacred day, because LHX is going to have a long journey. But the master is the leader after all, he likes to go his own way, let others dumbfounded. Why, because this route is uneven, and is quite serious.
But the master has his own way, he can magic.
This passage can be expressed in a sequence of length n a[i], A[i] Indicates the height of the section I of the road. After all, even if the master will use magic, he is a person, if the leader wants to cross this route, he must start from the 1th paragraph, go to the nth paragraph, from paragraph I to paragraph I+1 road need to consume | A[i+1]-a[i]| a little energy. In order to save energy, the master has resorted to his other magical magic. The Master's magic can exchange the height of two adjacent sections, and this magic does not need to spend extra energy. But the second use of magic, the exchange of two segments in the route in the position needs to be in the previous exchange of two sections after the road. That is, if A[J] and a[j+1] are exchanged, the next exchange A[k] and a[k+1] must satisfy the j Then, LHX to plan how to adjust the height of the road after crossing, so that the minimum physical exertion.

The topic is already obvious. For this kind of exchange is usually DP so how DP?

I also thought for a long time, thinking of how the DP "Shun push" pushed nearly 45MIN no fruit after I decided to give up. When I decided to do the next question when I found T3 compare water "and then go to T3" ....

When I finished the T3 was inspired by the T3 do not follow the walk backwards will be how.

Full proof: It is difficult to reverse.

For each point either swap to the back or do not change and after the change to the previous state has no effect.

Set F[i][0] represents the minimum cost of I moving I--and N

F[I][1] means I do not move the minimum cost of I--and N

The brute force enumeration J indicates that I moved to J, and calculated that the values in this state take the smallest.

How to transfer. For I, if I move, the value of the position of I must be a[i+1], and I move to J when the relative position of the i+1àj is constant so that the DP equation can be introduced

for (int i = n-2; i; i--) 
    {
        f[i][1] = min (f[i + 1][1] + ABS (A[i]-a[i + 1]), F[i + 1][0] + ABS (A[i]-a[i + 2] ));
        int tmp = f[i][0];
        for (int j = i+1; J < N; j + +) 
        {
            int tx =sum[j]-sum[i + 1] + ABS (A[J]-a[i]);
            if (TX + F[j + 1][1] + ABS (A[J + 1]-a[i]) < TMP) 
               tmp = tx + F[j + 1][1] + ABS (A[J + 1]-a[i]);
            if (TX + F[j + 1][0] + ABS (A[J + 2]-a[i]) < TMP && J! = n-1)
               tmp = tx + F[j + 1][0] + ABS (A[J + 2]-a[i] );
        }
        TMP = MIN (tmp, Sum[n]-sum[i + 1] + ABS (A[n]-a[i]));
        F[I][0] = tmp;
    }

Special deal with J = n–1 The value is complete the answer is min (f[1,0],f[1,1]).

T3 Resource Exploration

There are two versions of the game and I made a simpler version of it.

Title: Teaching mainly leads a group of Orzer to a Xiongqi local reconnaissance resources.
This place can be described in a nxm matrix A[i, J], while the master's position is located in the 1th row of the Matrix 1th column.
Each element of the Matrix A[i, J] is a positive integer that does not exceed NXM, and describes the type of resource located in this location as the A[i, J] class. The master is ready to select a sub-matrix as the scope of the survey, the upper left corner of the matrix is where the leader (1, 1). If a class of resources k is in the scope of the main survey to appear exactly once. Or if the Guru chooses (x, y) that is the lower-right corner of the sub-matrix, then there is only one a[i in this sub-matrix, J] (1≤i≤x,1≤j≤y) satisfies A[i, j]=k, then the K-class resource is considered a rare resource by the guru.
Now the question is, for all (x, y), ask if (x, y) as the lower-right corner of the sub-matrix, how many different kinds of resources are considered rare by the guru.

Input

The first line of the input consists of two positive integers n and M, followed by n rows, with m numbers per line, describing the Matrix A[i, J].

Output

In order to take care of the output problem of Vijos, set B[i, j] to indicate how many numbers happen once for the sub-matrices containing only the first I row and the first J column, then you want to output all B[i, j] and MoD 19900907.

The transition is in output.

For individual x, y I don't think of anything but violence.

But the problem is that calculating all the b[i,j] is an advantage: we don't consider the individual x, Y, but the impact of each resource on the total answer.

For the same resource on the same row, the location where the first occurrence occurs and the second occurrence is the location that is treated as a rare resource. If there is only one row, you can find the minimum and minor column numbers directly.

It is OK to maintain the minimum and minor number of columns as long as there are multiple lines.

T4: Permutation statistics

Title: For a given sequence of length n {b[n]}, ask how many sequence {A[n]} for all I satisfies: a[1]~a[i] This I number has exactly b[i] number small equals I. where {A[n]} is an arrangement of 1~n, that is, 1~n the n numbers occur exactly once in the sequence a[i].
The data ensures that at least one permutation satisfies the B sequence.

The topic title ...

I didn't even think of violence at the time of the game. Not to mention the best way to ensure that the first three questions no problem I only see the fourth question "about one hours left" so far I still do not violence to see the solution directly on the straight.

Portal àhttp://hi.baidu.com/qyjubriskxp/item/318f961166a07c12e3f98600

The following are the portals of the topic: vijosp1660–1663

https://www.vijos.org/p/1660

https://www.vijos.org/p/1661

https://www.vijos.org/p/1662

https://www.vijos.org/p/1663

True, resource exploration: https://www.vijos.org/p/1664 interested students can go and see

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.