您的位置:首页 > 其它

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

2016-03-07 21:10 225 查看
原题: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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: