力扣的题有空再探索复杂度更低的做法
class Solution {
public:
static bool cmp(vector<int> a,vector<int> b){
if(a[0]!=b[0])return a[0]<b[0];
else return a[1]<b[1];
}
int maxEnvelopes(vector<vector<int>>& envelopes) {
if(envelopes.size()<2)return envelopes.size();
sort(envelopes.begin(),envelopes.end(),cmp);
int len=envelopes.size();
int num[len];
fill(num,num+len,0);
num[0]=1;
int maxnum=1;
for(int i=1;i<len;i++){
int maval=0,maidx=-1;
for(int j=0;j<i;j++){
if(num[j]>maval && envelopes[j][0]<envelopes[i][0] && envelopes[j][1]<envelopes[i][1]){
maidx=j;
maval=num[j];
}
}
if(maidx==-1)num[i]=1;
else num[i]=maval+1;
maxnum=max(maxnum,num[i]);
}
return maxnum;
}
};