【最长上升子序列】北大 POJ 1631 Bridging signals

 

/* THE PROGRAM IS MADE BY PYY */
/*----------------------------------------------------------------------------//
    Copyright (c) 2012 panyanyany All rights reserved.

    URL   : http://poj.org/problem?id=1631
    Name  : 1631 Bridging signals
	Classification : 最长上升子序列

    Date  : Wednesday, July 11, 2012
    Time Stage : half an hour

    Result:
10420085	panyanyany
1631
Accepted	472K	125MS	C++
1557B	2012-07-11 07:29:31

Test Data :

Review :

//----------------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <string>

using namespace std ;

#define MEM(a, v)        memset (a, v, sizeof (a))    // a for address, v for value
#define max(x, y)        ((x) > (y) ? (x) : (y))
#define min(x, y)        ((x) < (y) ? (x) : (y))

#define INF     (0x3f3f3f3f)
#define MAXN	(40005)

#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)|1)
#define M(x, y)	(((x)+(y)) >> 1)

#define DB    //

int a[MAXN], order[MAXN];

int LIS(int a[], int n)
{
	int i, u, l, m, len;

	len = 1;
	MEM(order, INF); //	找上升子序列时初始化 INF,找下降子序列时初始化为0
	for (i = 0; i < n; ++i)
	{
		u = len;
		l = 1;
		while (l <= u)
		{
			m = (l + u) >> 1;
			if (order[m] < a[i])
				l = m + 1;
			else
				u = m - 1;
		}
		if (order[l] > a[i])
			order[l] = a[i];
		if (len < l)
			len = l;
//		printf("^ %d ^", l);
	}

	return len;
}

int main()
{
	int i, n, tc;
	while (scanf("%d", &tc) != EOF)
	{
		while (tc--)
		{
			scanf("%d", &n);
			for (i = 0; i < n; ++i)
				scanf("%d", a+i);
			printf("%d\n", LIS(a, n));
		}
	}
	return 0;
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

写代码的安徒生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值