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;
    }
  • 相关阅读:
    第一周学习总结
    《淘宝网》质量属性分析
    软件架构师如何工作
    MVC模式
    Python学习
    echarts-数据的视觉映射
    热词展示
    热词关系图
    offset、client、scroll三个系列对比,是否有边框 padding?是否有单位?
    元素滚动 scroll系列属性 如果内容溢出盒子、scroll返回的是内容的大小 是否带边框、单位?
  • 原文地址:https://www.cnblogs.com/hyfer/p/5811929.html
Copyright © 2011-2022 走看看