354. Russian Doll Envelopes
来源:互联网 发布:烟雾视频软件 编辑:程序博客网 时间:2024/05/16 17:25
Description:
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]).
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <memory.h>
- using namespace std;
- class Solution {
- public:
- static bool cmp1(pair<int,int> a,pair<int,int> b)
- {
- return a.first<b.first;
- }
- static bool cmp2(pair<int,int> a,pair<int,int> b)
- {
- return a.second<b.second;
- }
- int maxEnvelopes(vector<pair<int, int> >& envelopes) {
- sort(envelopes.begin(),envelopes.end(),cmp1);
- sort(envelopes.begin(),envelopes.end(),cmp2);
- int en[10000];
- memset(en,0,sizeof(en));
- int l=envelopes.size();
- int ans=0;
- for(int i=0;i<l;i++)
- {
- int w=envelopes[i].first;
- int h=envelopes[i].second;
- en[i]=1;
- for(int j=0;j<i;j++)
- {
- int nw=envelopes[j].first;
- int nh=envelopes[j].second;
- if(w>nw&&h>nh)
- en[i]=max(en[i],en[j]+1);
- }
- ans=max(ans,en[i]);
- }
- return ans;
- }
- };
阅读全文
0 0
- 354. Russian Doll Envelopes
- 354. Russian Doll Envelopes
- 354. Russian Doll Envelopes
- 354. Russian Doll Envelopes
- 354. Russian Doll Envelopes
- 354. Russian Doll Envelopes
- 354. Russian Doll Envelopes
- 354. Russian Doll Envelopes
- 354. Russian Doll Envelopes
- LeetCode 354. Russian Doll Envelopes
- leetcode 354. Russian Doll Envelopes
- [leetcode] 354. Russian Doll Envelopes
- leetcode.354. Russian Doll Envelopes
- leetcode 354. Russian Doll Envelopes
- leetcode 354.Russian Doll Envelopes
- LeetCode 354. Russian Doll Envelopes
- Leetcode-354. Russian Doll Envelopes
- [LeetCode]354. Russian Doll Envelopes
- 安卓音乐播放器,简单,开源
- javascript的window.ActiveXObject对象,区别浏览器的方法
- Easy Game
- linux下gpasswd命令
- MFC自定义消息
- 354. Russian Doll Envelopes
- B
- AVL树与红黑树比较
- win7使用apache2作文件服务器
- 希尔排序 Java实现
- 从今以往 勿复相思
- 普通摄像头的数据输出格式YUV与mjpeg之间联系、DCT离散余弦变换去噪跟压缩
- 消息队列选型
- 【codevs 1075】明明的随机数