Codevs 3641 God elect.

Source: Internet
Author: User

3641 God electtime limit: 1 sspace limit: 256000 KBtitle level: Golden GoldTitle Description Description

people all over the world have IQ IQ and the Emotional Quotient EQ . We use two numbers to denote the IQ and eq of a person, and the large number represents a higher IQ or EQ. Now there are n people in front of you , this n personal IQ and EQ are known, please choose as many as possible, asked to elect no two people i and J,i have an IQ greater than the IQ of J but I eq is less than J emotional quotient.

Enter a description Input Description

? first line a positive integer N , which represents the number of people. ? second line to article n+1 lines, two positive integers per line, respectively, representing each person's IQ and emotional quotient.

Output description Output Description

Only one row, for the maximum number of people selected.

Sample input Sample Input

3 the

Sample output Sample Output

<nobr>2 </nobr>

Data range and Tips Data Size & Hint

? n<=1000 ;  

/*basic idea: The IQ in descending order, and then according to this order, run the longest does not rise sub-sequence can be, nothing but the IQ of the high and low, as the original longest not rise sub-series array subscript just*/#include<iostream>using namespacestd; #include<cstdio>#defineN 1001intN; #include<algorithm>structpeo{intIq,love; intLine ;};intDp[n][n]; Peo Peo[n];voidinput () {scanf ("%d",&N);  for(intI=1; i<=n;++i) {scanf ("%d%d",&peo[i].iq,&peo[i].love); Peo[i].line=1; }}intCMP (Peo a,peo b) {returnA.iq>B.iq;}voidDP () {sort (peo+1, peo+n+1, CMP);  for(inti=n-1; i>=1;--i) for(intj=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; intmaxx=0;  for(intI=1; i<=n;++i)if(peo[i].line>Maxx) Maxx=Peo[i].line; cout<<maxx<<Endl; }intMain () {input ();    DP (); return 0;}
View Code

Codevs 3641 God elect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.