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 ...
随机推荐
- 使用CSS3 BACKFACE-VISIBILITY属性制作翻转动画效果
摘要: 通过backface-visibility:hidden;属性,我们可以使一个元素在翻转之后消失,这是可以使用另一个元素放在它的背面,从而制作出一种元素翻转之后出现另一个元素的效果. ... ...
- vue.js学习笔记之v-bind,v-on
v-bind 指令用于响应地更新 HTML 特性 形式如:v-bind:href 缩写为 :href; v-on 指令用于监听DOM事件 形式如:v-on:click 缩写为 @clic ...
- myeclipse注册码生成器
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader; public cl ...
- AIX修改用户密码登录不成功案例分享
背景:使用passwd XXXX fcesjaif,修改新密码仍然提示密码不正确.拒绝登录 a. 使用命令lsuser -f XXXX |grep -i successful 查看不成功的次数 chu ...
- 1-5Tomcat 目录结构 和 web项目目录结构
对应我的安装路径: web项目目录结构
- bcopy函数
函数原型:void bcopy(const void *src, void *dest, int n) 头文件:#include <string.h> 函数功能:将src指针指 ...
- wireshark使用方法(学习笔记一)
wireshark是非常流行的网络封包分析软件,功能十分强大.可以截取各种网络封包,显示网络封包的详细信息.使用wireshark的人必须了解网络协议,否则就看不懂wireshark了. 为了安全考虑 ...
- 转载--JAVA读取文件最佳实践
1. 前言 Java应用中很常见的一个问题,如何读取jar/war包内和所在路径的配置文件,不同的人根据不同的实践总结出了不同的方案,但其他人应用却会因为环境等的差异发现各种问题,本文则从原理上解释 ...
- django允许跨域备忘笔记
详细信息请拜读网址:https://github.com/ottoyiu/django-cors-headers/ 安装: 在virtaulenv环境中执行 pip install django-co ...
- 【LeetCode OJ】Flatten Binary Tree to Linked List
Problem Link: http://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/ The problem is ask ...