Hdu4512: gigo series of stories-perfect formation I (LICs)

Source: Internet
Author: User
Problem description gigo has been interested in the formation over the past few days.
One day, N people stood in front of him in sequence. Their heights were H [1], H [2]... H [N], gigo hopes to pick out some people from them to form a new formation. If the new formation meets the following three requirements, it is called a perfect formation:
  
1. The picked persons remain unchanged in the relative order of the original formation;
2. symmetric between the left and right. If m people form a new formation, the height of 1st people is the same as that of m people, and that of 2nd people is the same as that of m people, if M is an odd number, the person in the middle can be any;
3. The person from left to middle must increase his height. If H is used to represent the height of the new formation, then H [1] <H [2] <H [3]... <H [Mid].

Now, gigo wants to know: How many people can be selected to form a perfect formation?

 


Input T in the first line indicates a total of T groups of data (T <= 20 );
Input N (1 <= n <= 200) for each data group, and then input n integers in the next row, the height of the person standing in the original formation from left to right (50 <= H <= 250, especially short and tall ).


Output please output the maximum number of people that can form a perfect formation, and each group of data output occupies one row.


Sample Input

2351 52 51451 52 52 51

 

Idea: it is easy to think of turning the original string and then finding LICs,

# Include <stdio. h> # include <string. h ># include <algorithm> using namespace STD; int n, a [205], B [205], DP [205]; int LICs () {int Max, I, j, k; memset (DP, 0, sizeof (DP); max = 0; for (I = 1; I <= N; I ++) {k = 0; for (j = 1; j <= n-I + 1; j ++) {if (a [I] = B [J]) {If (J! = (N-I + 1) // does not match itself {If (DP [J] <(DP [k] + 2 )) // Add 2 DP [J] = DP [k] + 2 ;} else // matches itself {If (DP [J] <(DP [k] + 1 )) // Add only 1 DP [J] = DP [k] + 1 ;}} else if (a [I]> B [J] & DP [k] <DP [J]) k = J; If (max <DP [J]) max = DP [J] ;}} return Max ;}int main () {int T, I; scanf ("% d", & T); While (t --) {scanf ("% d", & N); for (I = 1; I <= N; I ++) scanf ("% d ", & A [I]); for (I = 1; I <= N; I ++) B [I] = A [n-I + 1]; printf ("% d \ n", LICs ();} return 0 ;}

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.