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 ...
随机推荐
- JDK配置
一.下载和安装 二.配置环境变量 1.计算机→属性→高级系统设置→高级→环境变量 2.系统变量→新建JAVA_HOME,值为jdk的安装目录(如C:\Java\jdk1.7.0) 3.系统变量→修改P ...
- C#关于导出excel的方法
一说到导出excel可能很多人都会觉得说直接利用npoi 导入导出excel格式的文件,那样非常方便,但是可能有些时候有的浏览器不支持,那么该怎么办呢,现在介绍一种纯C#的导出excel的方法,代码如 ...
- Dynamo涉及的算法和协议——p2p架构,一致性hash容错+gossip协议获取集群状态+向量时钟同步数据
转自:http://www.letiantian.me/2014-06-16-dynamo-algorithm-protocol/ Dynamo是Amazon的一个分布式的键值系统,P2P架构,没有主 ...
- cppcheck 下载与安装(Liunx)
下载网址:https://sourceforge.net/projects/cppcheck/files/cppcheck/ 选择安装包:cppcheck-1.75.tar.gz 解压安装包:tar ...
- JS实现表格的增删改
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/T ...
- JS判断是否已经到达页面底部
$(window).scroll(function(){ var scrollTop=$(this).scrollTop(); var scrollHeight=$(document).height( ...
- 4、android BroadcastReceiver详细用法
BroadcastReceiver也就是“广播接收者”的意思,顾名思义,它就是用来接收来自系统和应用中的广播. 在Android系统中,广播体现在方方面面,例如当开机完成后系统会产生一条广播,接收到这 ...
- SharePoint 2016 Beta 2 安装体验
博客地址:http://blog.csdn.net/FoxDave 最近忙碌了一段时间,2016正式版快要发布了,想尽快熟悉熟悉.2016不再提供免费版Foundation的支持,只有Server版本 ...
- app转让遇到的坑
家人共享的一部分 首先我们要符合app转让的一些基本规定,填写正确的信息去申请转让.(google会有很多正确的转让步骤),这里我就不多写出来了. 当接收到接受app的时候会出现一些想不到的问题. 其 ...
- Linq学习总结1--参考Linq技术详解
2个要点: 1.linq操作的集合必须实现IEnumerable接口,所以在这3.0之前为实现该接口的集合需通过Cast或TypeOf方法转换成可Linq的集合; 2.查询式和Lame那啥表达式都可以 ...