方法一,dp
如果 a[i]>a[j] ,那么dp[i]=max(dp[i],dp[j]+1)
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=1005;
int dp[maxn],a[maxn];
int main(){
int n;
while(scanf("%d",&n)==1){
for(int i=0;i<n;i++)scanf("%d",&a[i]);
int ans=-1;
for(int i=0;i<n;i++){
dp[i]=1;
for(int j=i-1;j>=0;j--)if(a[i]>a[j]&&dp[j]+1>dp[i])dp[i]=dp[j]+1;
if(ans<dp[i])ans=dp[i];
}
printf("%d\n",ans);
}
}
方法二,set
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
int main(){
int n,dat;
while(cin>>n){
multiset<int>myset;
multiset<int>::iterator pos;
for(int i=0;i<n;i++){
cin>>dat;
myset.insert(dat);
pos=myset.find(dat);
if(++pos!=myset.end())myset.erase(pos);
}
cout<<myset.size()<<endl;
}
}