标签:
Description
Input
Output
Sample Input
6 5 2 1 4 5 3 3 1 1 1 4 4 3 2 1
Sample Output
3 1 1
Hint
#include<cstdio>
int a[100001], f[100001];
int main()
{
int n, k, l, r, mid;
while (scanf("%d",&n)==1)
{
for (int i = 0; i < n; i++)
scanf("%d",&a[i]);
k = 0;
f[0] = -1; //赋初值,小于0即可
for (int i = 0; i < n; i++)
{
if (a[i] > f[k])
{
k++;
f[k] = a[i]; //每找到一个就保存到f【】数组里
}
else
{
l = 1, r = k;
while (l<=r) //判断此时的a[i]和f数组中各个值大小关系,直到找到最优值
{
mid = (l + r) / 2;
if (a[i] > f[mid])
l = mid + 1;
else
r = mid - 1;
}
f[l] = a[i];
}
}
printf("%d\n",k);
}
}
POJ - 3903 Stock Exchange(LIS最长上升子序列问题)
标签:
原文地址:http://www.cnblogs.com/hfc-xx/p/4725490.html