LIS

wikipedia
Description:
输入

第1行:1个数N,N为序列的长度(2 <= N <= 50000)
第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9)

输出

输出最长递增子序列的长度。

输入示例

8
5
1
6
8
2
4
5
10

输出示例

5

Code:

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=50050;
const int INF=0x3f3f3f3f;
int dp[maxn],a[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    fill(dp,dp+n,INF);
    for(int i=0;i<n;i++)
    {
        *lower_bound(dp,dp+n,a[i])=a[i];
    }
    cout<<lower_bound(dp,dp+n,INF)-dp<<endl;
}

The main problem solving idea is


So we can use a convenient function,such aslower_bound.
Click to know more about lower_bound
Honestly, I don't know what this has to do with DP, but it doesn't matter, I will always know it later.