题解 | #马戏团#

马戏团

https://www.nowcoder.com/practice/c2afcd7353f84690bb73aa6123548770

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

bool cmp(const pair<int, int>& a, const pair<int, int>& b)
{
    return a.first == b.first ? a.second > b.second : a.first < b.first;
}

int cal(vector<pair<int, int>>& nums, int n){
    sort(nums.begin(), nums.end(), cmp);
    
    vector<int> dp(n, 1);

    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            if(nums[i].second >= nums[j].second){
                dp[i] = max(dp[i], dp[j]+1);
            }
        }
    }

    int res = 1;
    for(int i=0; i<n; i++){
        res = max(res, dp[i]);
    }

    return res;
}

int main(){
    int n;
    while(cin >> n){
        vector<pair<int,int>> nums;
        int index, weight, height;
        for(int i=0; i<n; i++){
            cin >> index >> weight >> height;
            nums.push_back({weight, height});
        }

        cout << cal(nums, n) << endl;
    }
    return 0;
}





全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务