POJ 3903 —— Stock Exchange 最長上升子序列

原題:http://poj.org/problem?id=3903

題意:求最長上升子序列的個數;


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

int main()
{
	while(~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 pos = lower_bound(stack+1, stack+top+1, tmp) - stack;
				stack[pos] = tmp;
			}
		}
		printf("%d\n", top);
	}	
	return 0;
}


發佈了60 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章