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的更多相关文章

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

    https://leetcode.com/problems/russian-doll-envelopes/ You have a number of envelopes with widths and ...

  2. [LeetCode] 354. Russian Doll Envelopes 俄罗斯套娃信封

    You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...

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

    Leetcode354 暴力的方法是显而易见的 O(n^2)构造一个DAG找最长链即可. 也有办法优化到O(nlogn) 注意 信封的方向是不能转换的. 对第一维从小到大排序,第一维相同第二维从大到小 ...

  4. 【leetcode】354. Russian Doll Envelopes

    题目描述: You have a number of envelopes with widths and heights given as a pair of integers (w, h). One ...

  5. 354 Russian Doll Envelopes 俄罗斯娃娃信封

    You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...

  6. 354. Russian Doll Envelopes

    You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...

  7. [LeetCode] Russian Doll Envelopes 俄罗斯娃娃信封

    You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...

  8. [Swift]LeetCode354. 俄罗斯套娃信封问题 | Russian Doll Envelopes

    You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...

  9. 动态规划——Russian Doll Envelopes

    这个题大意很好理解,通过例子就能明白,很像俄罗斯套娃,大的娃娃套小的娃娃.这个题是大信封套小信封,每个信封都有长和宽,如果A信封的长和宽都要比B信封的要大,那么A信封可以套B信封,现在给定一组信封的大 ...

随机推荐

  1. HDFS snapshot操作实战

    Hadoop从2.1.0版开始提供了HDFS SnapShot的功能.一个snapshot(快照)是一个全部文件系统.或者某个目录在某一时刻的镜像.快照在下面场景下是非常有用:防止用户的错误操作:管理 ...

  2. java Servlet Filter 拦截Ajax请求

    /** * 版权:Copyright 2016-2016 AudaqueTech. Co. Ltd. All Rights Reserved. * 描述: * 创建人:赵巍 * 创建时间:2016年1 ...

  3. [手机取证] Jonathan Zdziarski公开的苹果iOS后门及POC视频

    Jonathan Zdziarski 近日在其推特上公布了此“后门”的研究及POC视频,并表示全球媒体“夸大”了此事,自己“从未表示过认为此后门与NSA的监控行为有关”. 视频 http://pan. ...

  4. 常用PHP函数类目录

    说明:用来记录我在开发过程中,经常用到的一些常用函数或者常用类. 常用函数 PHP常用函数 (1) 常用类 PHP表单数据校验类

  5. (链接)打印相关_.NET打印小资料

    掌握.NET中的日常打印:包括各个类的参数等 http://blog.csdn.net/dzweather/article/details/10171105 设置纸张大小 PrintDocument ...

  6. 利用SQL注入漏洞登录后台的实现方法

    利用SQL注入漏洞登录后台的实现方法 作者: 字体:[增加 减小] 类型:转载 时间:2012-01-12我要评论 工作需要,得好好补习下关于WEB安全方面的相关知识,故撰此文,权当总结,别无它意.读 ...

  7. openscales实现漂亮的冒泡效果

    使用的时候openscales 默认的冒泡效果确实有点简陋,想实现那种看着比较舒服的效果,只能自己定义了.参考现有的openscales实现的方式,它是通过控件的状态实现的,每个状态中使用Path绘制 ...

  8. openlayers优化项

    做了一个简单的样式,但是做的不怎么样:希望和大家讨论下载动态图那里,怎么能够提高效率,提高数据,能够快速反应:一般的处理方法是什么?

  9. html转义字符

    public static String toHTMLString(String in) { StringBuffer out = new StringBuffer(); for (int i = 0 ...

  10. ionic 里使用 iframe 可能遇到的问题

    无法访问外部url的问题--两个步骤解决: iframe的src属性用ng-src属性替代,并指明绑定对象: ng-src="{{targetUrl}}" 在controller里 ...