leetCode 354. Russian Doll Envelopes

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetCode 354. Russian Doll Envelopes相关的知识,希望对你有一定的参考价值。

You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the width and height of one envelope is greater than the width and height of the other envelope.

What is the maximum number of envelopes can you Russian doll? (put one inside other)

Example:
Given envelopes = [[5,4],[6,4],[6,7],[2,3]], the maximum number of envelopes you can Russian doll is 3 ([2,3] => [5,4] => [6,7]).

Subscribe to see which companies asked this question

题目分析:目标求最大的信封数目,要求宽和高都要小于某个信封才能放入这个信封。

先排序:先按照宽排序,然后按照长排序,从小到大

结合题目分析:比如 1,20 2,21 3,4 4,5 5,6 ==>([3,4] => [4,5] => [5,6]).  3个!!!

          1,20 2,21 3,4 4,7 8,5==>  2个!!!

宽和高的顺序不能变化。

用数组c记录第i个信封,最大的重叠数目。

maxLen(c[i])=maxLen(c[j+1]) 或者 1

 

 

 

以上是关于leetCode 354. Russian Doll Envelopes的主要内容,如果未能解决你的问题,请参考以下文章

leetcode@ [354] Russian Doll Envelopes (Dynamic Programming)

[动态规划] leetcode 354 Russian Doll Envelopes

LeetCode 354. Russian Doll Envelopes

leetcode354. Russian Doll Envelopes

第十二周 Leetcode 354. Russian Doll Envelopes(HARD) LIS问题

354. Russian Doll Envelopes