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