(DP) POJ 3298

Source: Internet
Author: User

Antimonotonicity
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 2913 Accepted: 1266

Description

I have a sequence Fred of length n comprised of integers between 1 and n inclusive. The elements of Fred is pairwise distinct. I want to find a subsequence Mary of Fred This is as long as possible and have the property that:

Mary0 > Mary1 < Mary2 > mary3 < ...

Input

The first line of input would contain a single integer T expressed in decimal with no leading zeroes. T Be is at most 50. T test cases would follow.

Each test case was contained on a. A line describing a test case is formatted as follows:

n Fred0 Fred1 Fred2 ... Fred n-1.

where n and each element of Fred are an integer expressed in decimal with no leading zeroes. No Line would have leading or trailing whitespace, and both adjacent integers on the same line would be separated by a Space. N would be is at most 30000.

Output

For each test case, output a single integer followed by a newline---the length of the longest subsequence MaryOf FredWith the desired properties.

Sample Input

45 1 2 3 4 55 5 4 3 2 15 5 1 4 2 35 2 4 1 3 5

Sample Output

1253

Source

Number of turn points +1

#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <string > #include <algorithm> #include <cstdlib>using namespace Std;int tt,a[30005];int main () {    int n,x1,x2 , K;    scanf ("%d", &tt);    while (tt--)    {        scanf ("%d", &n);        int Ans=1;        scanf ("%d", &x1);        k=2;        for (int i=2;i<=n;i++)        {            scanf ("%d", &x2);            if (x1>x2&&k!=1)            {                k=1;                ans++;            }            if (x1<x2&&k!=2)            {                k=2;                ans++;            }            x1=x2;        }        printf ("%d\n", ans);    }    return 0;}

  

(DP) POJ 3298

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.