2017年5月21日12:35:53354. Russian Doll Envelopes
来源:互联网 发布:淘宝助理导出宝贝 编辑:程序博客网 时间:2024/06/11 14:18
You have a number of envelopes with widths and heights given as a pair of integers (w, h)
. One envelope can fit into another if and only if both the width and height of one envelope is greater than the width and height of the other envelope.
What is the maximum number of envelopes can you Russian doll? (put one inside other)
Example:
Given envelopes = [[5,4],[6,4],[6,7],[2,3]]
, the maximum number of envelopes you can Russian doll is 3
([2,3] => [5,4] => [6,7]).
俄罗斯瓷娃娃问题
要是长宽比之前的小就可以套
bool cmp (pair<int, int> i, pair<int, int> j) { if (i.first == j.first) return i.second < j.second; return i.first < j.first; } class Solution { public: int maxEnvelopes(vector<pair<int, int>>& envelopes) { int N = envelopes.size(); vector<int> dp(N, 1); int mx = (N == 0) ? 0 : 1; sort(envelopes.begin(), envelopes.end(), cmp); for (int i = 0; i < N; i++) { for (int j = i - 1; j >= 0; j--) { if (envelopes[i].first > envelopes[j].first && envelopes[i].second > envelopes[j].second) { dp[i] = max(dp[i], dp[j] + 1); mx = max(dp[i], mx); } } } return mx; } };
给出一个长宽找出最长的 再找最宽 然后根据这个长宽找其余最大长宽 时间复杂度 n^2
阅读全文
0 0
- 2017年5月21日12:35:53354. Russian Doll Envelopes
- 【Leetcode】Russian Doll Envelopes
- 354. Russian Doll Envelopes
- Russian Doll Envelopes
- 354. Russian Doll Envelopes
- leetcode_354 Russian Doll Envelopes
- leetcode_354.Russian Doll Envelopes
- 354. Russian Doll Envelopes
- leetcode Russian Doll Envelopes
- LeetCode Russian Doll Envelopes
- Russian Doll Envelopes
- LeetCode -- Russian Doll Envelopes
- 【Leetcode】Russian Doll Envelopes
- 354. Russian Doll Envelopes
- Russian Doll Envelopes
- 354. Russian Doll Envelopes
- [LeetCode] Russian Doll Envelopes
- 354. Russian Doll Envelopes
- oracle的“over partition by”的用法,over不能单独使用,要和分析函数:rank(),dense_rank(),row_number()等一起使用。
- C语言动态内存分配中malloc与realloc有什么区别?
- 独立成分分析(Independent Component Analysis)
- BZOJ4885: [Lydsy2017年5月月赛]长方体
- SpringMVC HiddenHttpMethodFilter的使用
- 2017年5月21日12:35:53354. Russian Doll Envelopes
- CentOS安装VMwareTools出现的一些问题解决。
- 简明C语言教程(二十)浮点数存储所带来的问题
- linux mysql 授权
- socket通信之http-server
- BZOJ4886: [Lydsy2017年5月月赛]叠塔游戏
- 虚拟机类加载机制
- Jsp+Hibernate开发中遇到的问题 java.lang.ClassNotFoundException: org.hibernate.Session的解决
- 驱动程序——TLC7226——基于STM32F103