这种二维问题一般都是排序+dp,可以转化为LIS问题。
解法一:dp
状态转移方程为以当前数字结尾的最长序列长度。注意:此题不要用max,不然会超时。
class Solution:
def maxEnvelopes(self, envelopes: List[List[int]]) -> int:
if not envelopes: return 0
arrs = sorted(envelopes, key=lambda x: (x[0], x[1]))
dp = [1 for _ in envelopes]
ret = 1
for i in range(1, len(dp)):
for j in range(0, i):
if