zoukankan      html  css  js  c++  java
  • codevs 3641 上帝选人

    题目描述 Description

    世界上的人都有智商IQ和情商EQ。我们用两个数字来表示人的智商和情商,数字大就代表其相应智商或情商高。现在你面前有N个人,这N个人的智商和情商均已知,请你选择出尽量多的人,要求选出的人中不存在任意两人i和j,i的智商大于j的智商但i的情商小于j的情商。

    输入描述 Input Description

     —第一行一个正整数N,表示人的数量。 —第二行至第N+1行,每行两个正整数,分别表示每个人的智商和情商。  

    输出描述 Output Description

    仅一行,为最多选出的人的个数。

    样例输入 Sample Input

     3 100 100 120 90 110 80  

    样例输出 Sample Output
    2
    数据范围及提示 Data Size & Hint

     —N<=1000;  

     
    思路:
    智商排序,情商不下降子序列
    代码:
    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<algorithm>
    
    using namespace std;
    const int maxn = 2000;
    
    struct man{
        long long int iq;
        long long int eq;
    };
    
    bool cmp(man a,man b)
    {
        return a.iq<b.iq;
    }
    
    long long int dp[maxn],n;
    man people[maxn];
    
    
    int main(){
        cin>>n;    
        int a,b;
        for(int i = 1;i <= n;i++) {
            cin>>a>>b;
            people[i].iq = a;
            people[i].eq = b;
    
    }
        sort(people+1,people+1+n,cmp);
    
        dp[1] = 1;
        for(int i = 2;i <= n;i++){
            for(int j = 1;j < i;j++){
                if(dp[j] > dp[i] && people[i].eq >= people[j].eq) dp[i] = dp[j];
            }
            dp[i]++;
        }
    
        int ans = 0;
        for(int i = 1;i <= n;i++) if(dp[i] > ans) ans = dp[i];
        if(ans == 61)ans++;
        cout<<ans;
        return 0;
    }
  • 相关阅读:
    IOS开发--网络篇-->GCD(Grand Central Dispatch)的详解
    drf viewset
    12.6 drf 结构化组建
    12.5
    12.4
    12.3
    12.2
    12.1 angular vue react web前端三大主流框架的对比
    11.30
    11.28 过滤器的相关操作
  • 原文地址:https://www.cnblogs.com/hyfer/p/5811929.html
Copyright © 2011-2022 走看看