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

来源:互联网 发布:淘宝恒源祥羊毛衫价格 编辑:程序博客网 时间:2024/04/30 14:25

原题: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;}


0 0
原创粉丝点击