C++ 9-line Short and Clean O(nlogn) solution (plus classic O(n^2) dp solution).
///O(nlogn)\n\n    struct Solution {\n        int maxEnvelopes(vector<pair<int, int>>& es) {\n            sort(es.begin(), es.end(), [](pair<int, int> a, pair<i
    ///O(nlogn)\n\n    struct Solution {\n        int maxEnvelopes(vector<pair<int, int>>& es) {\n            sort(es.begin(), es.end(), [](pair<int, int> a, pair<int, int> b){\n                return a.first < b.first || (a.first == b.first && a.second > b.second);});\n            vector<int> dp;\n            for (auto e : es)\n            {\n                auto iter = lower_bound(dp.begin(), dp.end(), e.second);\n                if (iter == dp.end())\n                    dp.push_back(e.second);\n                else if (e.second < *iter)\n                    *iter = e.second;\n            }\n            return dp.size();\n        }\n    };\n\n    ///DP\n    \n    struct Solution {\n        int maxEnvelopes(vector<pair<int, int>>& envelopes) {\n            if (envelopes.empty()) return 0;\n            sort(envelopes.begin(), envelopes.end());\n            vector<int> dp(envelopes.size(), 1);\n            for (int i = 0; i < envelopes.size(); ++i)\n                for (int j = 0; j < i; ++j)\n                    if (envelopes[j].first < envelopes[i].first && envelopes[j].second < envelopes[i].second)\n                        dp[i]  = max(dp[i] , dp[j] + 1);\n            return *max_element(dp.begin(), dp.end());\n        }\n    };
[]