#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int dp[100000];
int a[100000];
int b[100000];
int main()
{
int i = 0;
while (cin >> a[i])i++;
for (int x = 0;x < i;x++)b[x] = a[i - x - 1];
fill(dp, dp + i, 1000000);
for (int j = 0;j < i;j++)
{
*lower_bound(dp, dp + i, b[j]) = b[j];
}
cout << lower_bound(dp, dp + i, 1000000) - dp<<endl;
fill(dp, dp + i, 1000000);
for (int j = 0;j < i;j++)
{
*lower_bound(dp, dp + i, a[j]) = a[j];
}
cout << lower_bound(dp, dp + i, 1000000) - dp;
system("pause");
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int dp[100000];
int a[100000];
int b[100000];
int main()
{
int i = 0;
while (cin >> a[i])i++;
for (int x = 0;x < i;x++)b[x] = a[i - x - 1];
fill(dp, dp + i, 1000000);
for (int j = 0;j < i;j++)
{
*lower_bound(dp, dp + i, b[j]) = b[j];
}
cout << lower_bound(dp, dp + i, 1000000) - dp<<endl;
fill(dp, dp + i, 1000000);
for (int j = 0;j < i;j++)
{
*lower_bound(dp, dp + i, a[j]) = a[j];
}
cout << lower_bound(dp, dp + i, 1000000) - dp;
system("pause");
return 0;
这里最后要说明一下,使用lower_bound函数求出的序列是严格最长上升序列,也就是说对于每一项i>j 都满足a[i]>a[j],
而使用的是upper_bound的话就可以取等号,在导弹拦截那道题中,第一问是可以取等号的,而第二问是不可以的,这里一定要注意