http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1134&judgeId=529543
<nobr aria&#45;hidden="true"> dp[len] </nobr> <math xmlns="http&#58;&#47;&#47;www&#46;w3&#46;org&#47;1998&#47;Math&#47;MathML"> <mi> d </mi> <mi> p </mi> <mo stretchy="false"> [ </mo> <mi> l </mi> <mi> e </mi> <mi> n </mi> <mo stretchy="false"> ] </mo> </math>表示长度为l <nobr aria&#45;hidden="true"> en </nobr> <math xmlns="http&#58;&#47;&#47;www&#46;w3&#46;org&#47;1998&#47;Math&#47;MathML"> <mi> e </mi> <mi> n </mi> </math>的序列中,最后一个数的多少

#include"bits/stdc++.h"
using namespace std;
const int maxn=1e5+5;
int dp[maxn];
int main()
{
    int N;
    while(cin>>N)
    {
        memset(dp,-0x3f,sizeof(dp));

        int len=1;
        cin>>dp[1];
        for(int i=1;i<N;i++)
        {
            int t;
            cin>>t;
            if(t>dp[len])dp[++len]=t;
            else
            {
                int pos=upper_bound(dp+1,dp+1+len,t)-dp;
                dp[pos]=t;
            }
        }
        cout<<len<<endl;
    }
}