https://leetcode.com/problems/russian-doll-envelopes/description/
//矩形嵌套 DP
bool cmp(pair<int,int>a, pair<int, int>b)
{
if(a.first==b.first) return a.second<=b.second;
return a.first< b.first;
}
class Solution {
public:
int maxEnvelopes(vector<pair<int, int>>& envelopes) {
int result = 0;
int len = envelopes.size();
vector<int> dp(len,1);
sort(envelopes.begin(), envelopes.end(),cmp); //pair中的first排序
for(int i=0; i<len; i++){
for(int j=0; j<len; j++){
if(envelopes[j].first < envelopes[i].first && envelopes[j].second < envelopes[i].second){
dp[i] = max(dp[i], dp[j]+1);
}
}
result = max(result, dp[i]);
}
return result;
}
};