| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
 本帖最后由 糖逗 于 2020-7-2 13:19 编辑  
 
题目描述: 
- 有个马戏团正在设计叠罗汉的表演节目,一个人要站在另一人的肩膀上。出于实际和美观的考虑,在上面的人要比下面的人矮一点且轻一点。已知马戏团每个人的身高和体重,请编写代码计算叠罗汉最多能叠几个人。
 
  
- 示例:
 
  
- 输入:height = [65,70,56,75,60,68] weight = [100,150,90,190,95,110]
 
 - 输出:6
 
 - 解释:从上往下数,叠罗汉最多能叠 6 层:(56,90), (60,95), (65,100), (68,110), (70,150), (75,190)
 
 - 提示:
 
  
- height.length == weight.length <= 10000
 
  复制代码 
 
- bool cmp(pair<int, int> & a, pair<int, int> &b){
 
 -         if(a.first < b.first) return true;
 
 -         else if(a.first == b.first) return (a.second > b.second) ? true : false;
 
 -         else return false;
 
 -     }
 
 - class Solution {
 
 - public:
 
 -     int bestSeqAtIndex(vector<int>& height, vector<int>& weight) {
 
 -         int len = height.size();
 
 -         vector<pair<int, int> > temp(len);
 
 -         for(int i = 0; i < len; i++){
 
 -             temp[i].first = height[i];
 
 -             temp[i].second = weight[i];
 
 -         }
 
 -         sort(temp.begin(), temp.end(), cmp);
 
 -         //for(auto it : temp){
 
 -             //cout << it.first << " " << it.second << endl;
 
 -         //}
 
 -         vector<int> dp;
 
 -         for(int i = 0; i < len ; i++){
 
 -             int id = lower_bound(dp.begin(), dp.end(), temp[i].second) - dp.begin();
 
 -             cout << id << endl;
 
 -             if(id == dp.size()) dp.push_back(temp[i].second);//该数字在dp中没有出现过
 
 -             else dp[id] = temp[i].second;
 
 -         }
 
 -         return dp.size();
 
 -     }
 
 - };
 
  复制代码 
 
 
注意事项:lower_bound参考链接:https://www.cnblogs.com/Tang-tangt/p/9291018.html |   
 
 
 
 |