POJ 1631 —— Bridging signals 最长上升子序列

原题:http://poj.org/problem?id=1631

题意:有n个数,求最长上升子序列的个数;


#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 40000+10;
int stack[maxn];
int cas, n;

int main()
{
	scanf("%d", &cas);
	while(cas--)
	{
		scanf("%d", &n);
		int top = 0;
		stack[top] = -1;
		for(int i = 1;i<=n;i++)
		{
			int tmp;
			scanf("%d", &tmp);
			if(tmp > stack[top])
				stack[++top] = tmp;
			else
			{
				int l = 1, r = top;
				int mid;
				while(l <= r)
				{
					mid = (l+r)/2;
					if(tmp > stack[mid])
						l = mid+1;	
					else
						r = mid-1;
				}
				stack[l] = tmp;
			}
		}
		printf("%d\n", top);
	}	
	return 0;
}


你可能感兴趣的:(LIS)