Vawio Sequence
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
3
-
描述
-
Vawio Sequence is very funny,it is a sequence of integers. It has some interesting properties.· Vawio is of odd length i.e. L = 2*n + 1.· The first (n+1) integers of Vawio sequence makes a strictly increasing sequence.· The last (n+1) integers of Vawio sequence makes a strictly decreasing sequence.· No two adjacent integers are same in a Vawio sequence.For example 1, 2, 3, 4, 5, 4, 3, 2, 0 is an Vawio sequence of length 9. But 1, 2, 3, 4, 5, 4, 3, 2, 2 is not a valid Vawio sequence. In this problem, you will be given a sequence of integers. You have to find out the length of the longest Vawio sequence which is a subsequence of the given sequence. Consider, the given sequence as :
1 2 3 2 1 2 3 4 3 2 1 5 4 1 2 3 2 2 1.
Here the longest Wavio sequence is : 1 2 3 4 5 4 3 2 1. So, the output will be 9.-
输入
-
The input file contains less than 75 test cases. The description of each test case is given below: Input is terminated by end of file.
Each set starts with a postive integer, N(1<=N<=10000). In next few lines there will be N integers
输出
- For each set of input print the length of longest Vawio sequence in a line. 样例输入
-
10 1 2 3 4 5 4 3 2 1 10 19 1 2 3 2 1 2 3 4 3 2 1 5 4 1 2 3 2 2 1 5 1 2 3 4 5
样例输出
-
9 9 1
来源
- 原创 上传者
-
TC_胡仁东
-
The input file contains less than 75 test cases. The description of each test case is given below: Input is terminated by end of file.
题意:n个数的序列,求长度为奇数的最大序列,这个序列满足前n+1个数单调递增,后n+1个数单调递减,且每个数各不相同。
思路:正反求两次LIS即可,要用二分法。
代码:
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define pi acos(-1.0)
#define eps 1e-6
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define DBG pf("Hi\n")
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
#define mod 1000000009
const int maxn = 10005;
int a[maxn],b[maxn],g[maxn];
int aa[maxn],bb[maxn];
int n;
void solve(int a[],int aa[],int g[])
{
for (int i=0;i<=n;i++) g[i]=INF;
for (int i=1;i<=n;i++)
{
int k=lower_bound(g+1,g+n+1,a[i])-g;
aa[i]=k;
g[k]=a[i];
}
}
int main()
{
//#ifndef ONLINE_JUDGE
// freopen("C:/Users/lyf/Desktop/IN.txt","r",stdin);
//#endif
int i,j;
while (~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];
solve(a,aa,g);
solve(b,bb,g);
int ans=0;
for (i=1;i<=n;i++)
{
int x=min(aa[i],bb[n-i+1]);
ans=max(ans,2*x-1);
}
printf("%d\n",ans);
}
return 0;
}