uva 10534 波浪字符串

#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <queue>
using namespace std;

///宏定义
const int INF = 20000000;
const int maxn = 10010;
///全局变量 和 函数
//
int N;
int a1[maxn];
int a2[maxn];
int d1[maxn];
int d2[maxn];
int lis(int *a1, int *a2, int N)
{
	int i, j;
	//求a1最长上升子序列数组 O(nlogn)
	int g[maxn];
	for (i = 1; i <= N; i++)
	{
		g[i] = INF;
	}
	for (i = 0; i < N; i++)
	{
		int k = lower_bound(g + 1, g + N + 1, a1[i]) - g;
		d1[i] = k;
		g[k] = a1[i];
	}
         //求a2最长上升子序列数组
	for (i = 1; i <= N; i++)
	{
		g[i] = INF;
	}
	for (i = 0; i < N; i++)
	{
		int k = lower_bound(g + 1, g + N + 1, a2[i]) - g;
		d2[i] = k;
		g[k] = a2[i];
	}
         
	int ans = 1;
	for (i = 0; i < N; i++)
	{
		ans = max(ans, min(d1[i], d2[N - i - 1]) * 2 - 1);
	}
	//
	return ans;
}
int main()
{
	freopen("D:\\input.txt", "r", stdin);
	//
	int i, j;
	while (scanf("%d", &N) != EOF)
	{
		for (i = 0; i < N; i++)
		{
			int tmp;
			scanf("%d", &tmp);
			a1[i] = tmp;
			a2[N - i - 1] = tmp;
		}
		int ans = lis(a1, a2, N);
		printf("%d\n", ans);
	}

	//
	return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值