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

    3641 上帝选人

     时间限制: 1 s
     空间限制: 256000 KB
     题目等级 : 黄金 Gold
    题目描述 Description

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

    输入描述 Input Description

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

    输出描述 Output Description

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

    样例输入 Sample Input

     3 100 100 120 90 110 80  

    样例输出 Sample Output

    <nobr>2 </nobr>

    数据范围及提示 Data Size & Hint

     —N<=1000  

    /*基本思路:先把IQ按照降序排序,再根据这个顺序,跑一遍最长不上升子序列就可以了,无非就是把IQ的高低,作为了原来最长不上升子序列的数组下标而已*/
    #include<iostream>
    using namespace std;
    #include<cstdio>
    #define N 1001
    int n;
    #include<algorithm>
    struct Peo{
        int iq,love;
        int line;
    };
    int dp[N][N];
    Peo peo[N];
    void input()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
        {
            scanf("%d%d",&peo[i].iq,&peo[i].love);
            peo[i].line=1;
        }
    }
    int cmp(Peo a,Peo b)
    {
        return a.iq>b.iq;
    }
    void DP()
    {
        sort(peo+1,peo+n+1,cmp);
        for(int i=n-1;i>=1;--i)
          for(int j=i+1;j<=n;++j)
          if(peo[i].love>=peo[j].love&&peo[j].line+1>peo[i].line)
          peo[i].line=peo[j].line+1;
        int maxx=0;
        for(int i=1;i<=n;++i)
        if(peo[i].line>maxx)
        maxx=peo[i].line;
        cout<<maxx<<endl;
        
    }
    int main()
    {
        input();
        DP();
        return 0;
    }
    View Code
  • 相关阅读:
    Nginx配置文件详解
    JVM调优—性能分析神器-JProfiler详解
    Navicat Premium 15破解
    Nginx配置反向代理,负载均衡,动静分离,高可用
    Nginx安装和常用命令
    Spring中ApplicationContextAware的作用
    java中发起http和https请求
    MySql高可用架构
    matlab画3维meshgrid/plot3/mesh/surf的用法
    如何规范地编写一个MATLAB函数文件
  • 原文地址:https://www.cnblogs.com/c1299401227/p/5313162.html
Copyright © 2011-2022 走看看