hdu4512---吉哥系列故事——完美队形I

来源:互联网 发布:买家怎么申请淘宝客 编辑:程序博客网 时间:2024/05/16 07:57

Problem Description
  吉哥这几天对队形比较感兴趣。
  有一天,有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] … h[n],吉哥希望从中挑出一些人,让这些人形成一个新的队形,新的队形若满足以下三点要求,则称之为完美队形:
  
  1、挑出的人保持他们在原队形的相对顺序不变;
  2、左右对称,假设有m个人形成新的队形,则第1个人和第m个人身高相同,第2个人和第m-1个人身高相同,依此类推,当然,如果m是奇数,中间那个人可以任意;
  3、从左到中间那个人,身高需保证递增,如果用H表示新队形的高度,则H[1] < H[2] < H[3] …. < H[mid]。

  现在吉哥想知道:最多能选出多少人组成完美队形?

Input
  第一行输入T,表示总共有T组数据(T <= 20);
  每组数据先输入原先队形的人数n(1<=n <= 200),接下来一行输入n个整数,表示按顺序从左到右原先队形位置站的人的身高(50 <= h <= 250,不排除特别矮小和高大的)。

Output
  请输出能组成完美队形的最多人数,每组数据输出占一行。

Sample Input

2 3 51 52 51 4 51 52 52 51

Sample Output

3 4

Source
2013腾讯编程马拉松初赛第二场(3月22日)

Recommend
liuyiding | We have carefully selected several similar problems for you: 5177 5173 5169 5168 5165

LCIS的简单应用

/*************************************************************************    > File Name: hdu4512.cpp    > Author: ALex    > Mail: zchao1995@gmail.com     > Created Time: 2015年02月21日 星期六 18时42分55秒 ************************************************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double pi = acos(-1);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;typedef pair <int, int> PLL;const int N = 220;int dp[N][N];int arr[N];int rarr[N];int main (){    int t;    scanf("%d", &t);    while (t--)    {        int n;        scanf("%d", &n);        for (int i = 1; i <= n; ++i)        {            scanf("%d", &arr[i]);            rarr[n - i + 1] = arr[i];        }        memset (dp, 0, sizeof(dp));        for (int i = 1; i <= n; ++i)        {            int maxs = 0;            for (int j = 1; j <= n; ++j)            {                dp[i][j] = dp[i - 1][j];                if (arr[i] > rarr[j] && maxs < dp[i][j])                {                    maxs = dp[i][j];                }                if (arr[i] == rarr[j])                {                    dp[i][j] = maxs + 1;                }            }        }        int ans = 0;        for (int i = 1; i <= n; ++i)        {            if (ans < 2 * dp[i][n - i + 1] - 1)            {                ans = 2 * dp[i][n - i + 1] - 1;            }        }        for (int i = 1; i <= n; ++i)        {            for (int j = i + 1; j <= n; ++j)            {                if (arr[i] == arr[j])                {                    ans = max (ans, dp[i][n - j + 1] * 2);                }            }        }        printf("%d\n", ans);    }    return 0;}
1 1
原创粉丝点击