An intuitive DP - should be 'medium'.

class Solution {
public:
int maxEnvelopes(vector<pair<int, int>>& envelopes) {
int n = envelopes.size();
if (!n) return ;
if (n == ) return ; // Sort by Area
sort(envelopes.begin(), envelopes.end(), [](const pair<int, int> &e1, const pair<int, int> &e2){
return (e1.first *e1.second) < (e2.first *e2.second);
}); int ret = ;
vector<int> dp(n, );
for(int i = ; i < n; i ++)
{
pair<int, int> &ce = envelopes[i];
for(int j = ; j < i; j ++)
{
pair<int, int> &cp = envelopes[j];
if((ce.first > cp.first && ce.second > cp.second)
)
{
dp[i] = max(dp[i], dp[j] + );
}
ret = max(ret, dp[i]);
}
} return ret;
}
};

LeetCode "Russian Doll Envelopes"的更多相关文章

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

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

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

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

  3. [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 ...

  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 envel ...

  5. 【leetcode】354. Russian Doll Envelopes

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

  6. [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 ...

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

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

  8. 动态规划——Russian Doll Envelopes

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

  9. 354. Russian Doll Envelopes

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

随机推荐

  1. gitgub利用客户端实现简单的上传和同步

    新建项目 打开客户端(将项目拷贝到本地) 选择要clone到的文件夹 想该文件夹中,导入自己需要上传的代码 然后,在网站上登录自己的gitgub,就可以看到刚才上传的项目了╮(╯▽╰)╭

  2. 饮水思源——python中常用基础类源码解析

    1.bool类 2.int类 3.long类 4.float类 5.str类 6.list类 7.tuple类 8.dict类 9.collections类 Counter类:为hashable对象计 ...

  3. 线性布局通过适配器可以动态加载view

    因为适配器的getView的返回对象是view, 所以线性布局的对象可以通过addView动态加载适配器的getView 举例: mTestAdapter = new ListAdapter(this ...

  4. 关于DButils的简单介绍

    android中的orm框架,一行代码就可以进行增删改查:支持事务,默认关闭:可通过注解自定义表名,列名,外键,唯一性约束,NOT NULL约束,CHECK约束等(需要混淆的时候请注解表名和列名)等等 ...

  5. cocos2d-x 中的基本概念

    在 cocos2d-x 开头配置(Windows 平台)中,介绍了新建工程,这篇就介绍下 cocos2d-x 的一些概念.(前提是需要有C++的面向对象的基本知识和C++11的常用知识) 层,场景,导 ...

  6. js面向对象组件

    1.包装对象 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" ...

  7. 【63测试20161111】【BFS】【DP】【字符串】

    第一题: tractor 题目描述 农场上有N(1 <= N <= 50,000)堆草,放在不同的地点上.FJ有一辆拖拉机,也在农场上.拖拉机和草堆都表示为二维平面上的整数坐标,坐标值在1 ...

  8. php函数的可变参数

    <?php function add() { $arr = func_get_args(); //func_num_args() $sum =0; for($i=0;$i<count($a ...

  9. kernel source reading notepad

    __init ,标记内核启动时所用的初始化代码,内核启动完成后就不再使用.其所修饰的内容被放到.init.text section中 __exit,标记模块退出代码,对非模块无效 to be cont ...

  10. 例子:Alarm Clock with voice Commands Sample

    通过本例子学习: 如何使用自定义字体文件(.TTF) 如何播放声音 动画的使用 Speech 设置闹铃 应用 设置 数据存储到IsolatedStorage 如何使用自定义字体文件(.TTF) < ...