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. linux下打包命令的使用

    Unix系统业务使用(特别是数据管理与备份)中,经过一番研究.整理后,充分利用Unix系统本身的命令tar.cpio和compress等来做到打包和压缩,使之充当类似DOS下的压缩软件,同时在Unix ...

  2. java程序

    package Dome3; import java.awt.Button; import java.awt.FlowLayout; import java.awt.Frame; import jav ...

  3. iOS开发UI篇—iPad开发中得modal介绍

    iOS开发UI篇—iPad开发中得modal介绍 一.简单介绍 说明1: 在iPhone开发中,Modal是一种常见的切换控制器的方式 默认是从屏幕底部往上弹出,直到完全盖住后面的内容为止 说明2: ...

  4. 【代码】verilog之:电子钟

    功能:显示时分秒,能够设置时间. 实现:两个按键,一个进入设置,一个加数字.显示用LCD5110 用状态机实现,总共四种状态 idle(正常运行)——s_hour(时设置状态)——s_min(分设置状 ...

  5. 常用的获取时间差的sql语句

    "select count(*) from [注册] where datediff(day,time,getdate())<1";//获取当天注册人员数 sql=" ...

  6. SqlServer调用CLR服务

    作用 从数据库发起对外部服务的请求. 应用场景 心跳监测 定时启动站点 服务实现 代码部分(C#) using System; using System.Net; publicpartialclass ...

  7. WeX5 快速开发平台 V3.6 正式版发布

    WeX5 V3.6 正式版核心特性:一.打包特性增强: 1- 提供多WebView选择,引入腾讯X5引擎,可自动适配移动设备环境进行切换,使通过X5打包生成的App具备更高的兼容性及更小的文件尺寸: ...

  8. Linux下使用yum安装MariaDB

    版本:centos7 Linux下安装MariaDB官方文档参见:https://mariadb.com/kb/zh-cn/installing-mariadb-with-yum/ 1.创建Maria ...

  9. yum命令详解

    yum(全 称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载 ...

  10. UVA 10407 差分思想的运用

    就是每两项相减,肯定能被模数整除. #include <iostream> #include <cstring> #include <cstdio> #includ ...