LeetCode "Russian Doll Envelopes"
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"的更多相关文章
- [LeetCode] Russian Doll Envelopes 俄罗斯娃娃信封
You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...
- leetcode@ [354] Russian Doll Envelopes (Dynamic Programming)
https://leetcode.com/problems/russian-doll-envelopes/ You have a number of envelopes with widths and ...
- [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 ...
- 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 ...
- 【leetcode】354. Russian Doll Envelopes
题目描述: You have a number of envelopes with widths and heights given as a pair of integers (w, h). One ...
- [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 ...
- 354 Russian Doll Envelopes 俄罗斯娃娃信封
You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...
- 动态规划——Russian Doll Envelopes
这个题大意很好理解,通过例子就能明白,很像俄罗斯套娃,大的娃娃套小的娃娃.这个题是大信封套小信封,每个信封都有长和宽,如果A信封的长和宽都要比B信封的要大,那么A信封可以套B信封,现在给定一组信封的大 ...
- 354. Russian Doll Envelopes
You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...
随机推荐
- 关于JAVA EE项目在WEB-INF目录下的jsp页面如何访问WebRoot中的CSS和JS文件
找了这么久资料,总算解决了 感谢博客园:http://www.cnblogs.com/xsht/p/5275081.html 感谢百度:http://zhidao.baidu.com/link?url ...
- ijg库的使用的几点注意
ijg库(http://www.ijg.org/)是用于处理jpeg解码和压缩的库,最新版本为2014发布的版本,可以在官网中下载jpegsr9a.zip 使用vs中个nmake 进行编译,对于这个版 ...
- 20169212《Linux内核原理与分析》第二周作业
<Linux内核原理与分析>第二周作业 这一周学习了MOOCLinux内核分析的第一讲,计算机是如何工作的?由于本科对相关知识的不熟悉,所以感觉有的知识理解起来了有一定的难度,不过多查查资 ...
- MFC List Control 控件添加单元格编辑,实现可编辑重写
在实现随机生成四则运算的个人项目中,目前已经完成基本功能,想要把程序变成一个Windows界面的程序.原本以为学习过MFC,应该很快就能完成.但是由于以前用的都是VC6.0,这次用了VS2010,稍微 ...
- iOS开发Swift篇—(四)运算符
iOS开发Swift篇—(四)运算符 一.运算符 1.Swift所支持的部分运算符有以下一些 赋值运算符:= 复合赋值运算符:+=.-= 算术运算符:+.-.*./ 求余运算符:% 自增.自减运算符: ...
- 爱壁纸 站立会议(六)--Spring阶段总结会议
爱壁纸 站立会议(六)--Spring阶段总结会议 一.会议时间 2014年4月15日 星期三 21:00-21:20 今天是spring阶段最后一天,大家都对这一星期的任务概况做出了总结所以时间稍微 ...
- vs2008编译openssl问题
运行openssl demo 时,debug 版本正常,release 版本报异常:OPENSSL_Uplink(585E6000,08): no OPENSSL_Applink .demo 编译环境 ...
- c/c++面试题(3)strcat/strcmp/strlen/strcpy的实现
1.编写一个函数实现strlen以及strcpy函数. strcpy函数. 后面的字符串拷贝到一个字符数组中,要求拷贝好的字符串在字符数组的首 地址,并且只拷贝到'\0'的位置.原型是 char* m ...
- [深入Python]__new__和__init__
class A(object): def __init__(self): print "init" def __new__(cls,*args, **kwargs): print ...
- 使用PHPUnit + Selenium进行自动化测试
project: blog target: how-to-use-phpunit-selenium-test.md date: 2015-12-22 status: publish tags: - S ...