The hang-gliding of the Strange thief Kidd

Source: Internet
Author: User

The gliding wing of the strange Thief Kidd
Total time limit:
1000ms
Memory Limit:
65536kB
Describe

The Pirate Kidd is a legendary thief with a special focus on jewelry as a super thief. His most prominent place was that he was able to escape the heavy containment of the village police, which was largely thanks to the easy-to-operate glider he was carrying.

One day, the strange thief Kidd as usual stole a precious diamond, but was Conan children saw through the camouflage, and his glider wing of the power plant was Conan kicked out of the football destroyed. The last resort was to escape from the damage of the gliding wing only.

Suppose a total of n buildings in a city are lined up in a single line, each building has a different height. At the beginning, The strange thief Kidd can be at the top of any building. He can escape in one direction, but cannot change direction halfway (because the senjing will chase behind). As the glider was damaged, he could only glide down (ie: only from the higher building to the lower building). He wants to go through the top of different buildings as much as possible, which can slow down the impact and reduce the likelihood of injury. May I ask how many different buildings he can pass at the top (including the original building)?

Input
the first line of input data is an integer k (k < 100), which represents a K-group of test data.
Each set of test data contains two lines: The first line is an integer n (n < 100), representing N buildings. The second line contains n different integers, each of which corresponds to the height of a building H (0 < H < 10000), given in the order in which the buildings are arranged.
Output
for each set of test data, the output line contains an integer that represents the maximum number of buildings that can be passed by the monster Thief Kidd.
Sample input
38300 207 155 299 298 170 158 65865 158 170 298 299 155 207 300102 1 3 4 5 6 7 8 9 10
Sample output
669

  When we see the topic, the first reaction is the longest descent subsequence, in fact, this is really the longest descent subsequence, but we have to note that at the beginning, The strange thief Kidd can be at the top of any building. He can escape in one direction, but cannot change direction halfway (because the senjing will chase behind). Hey? What does this mean, not necessarily the two-way Ah! Well, think of here, you have the approximate algorithm to design out, yes, the two-way longest descending sub-sequence ... (The above name, purely self-created, if there is a similar, purely coincidental). So the next step is the code implementation problem. The first is the two-way storage problem, we can open a a[2][101] to record the height, wherein, a[1][i] represents the height from left to right to the first building, A[2][i] represents the height from right to left the first building. Similarly, we set f[2][101] to record the number of buildings that pass from left to right (from right to left) to the first building, and then sweep the F array once to find the maximum value. The next step is the code.
1  ProgramNOI4977;2 var3F:Array[1..2,0..101] ofLongint;4A:Array[1..2,0..101] ofLongint;5 I,j,k,n,m,max:longint;6 begin7 Readln (m);8       fork:=1  toM Do9      beginTenFillchar (F,sizeof (f),0); One READLN (n); A            fori:=1  toN Do -               begin -Read (a[1, I]); thea[2, n-i+1]:=a[1, I]; -               End; -f[1, n]:=1; -f[2, n]:=1; +            fori:=n-1 Downto 1  Do -               begin +max:=0; A                     forj:=i+1  toN Do at                        if(a[1, i]>a[1, j]) and(f[1, J]>max) Then -max:=f[1, j]; -f[1, i]:=max+1; -               End; -            fori:=n-1 Downto 1  Do -               begin inmax:=0; -                     forj:=i+1  toN Do to                        if(a[2, i]>a[2, j]) and(f[2, J]>max) Then +max:=f[2, j]; -f[2, i]:=max+1; the               End; *max:=0; $            fori:=1  toN DoPanax Notoginseng               if(max<f[1, I]) Then -max:=f[1, I]; the            fori:=1  toN Do +               if(max<f[2, I]) Then Amax:=f[2, I]; the Writeln (max); +      End; - End.

The hang-up of the strange thief Kidd

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.