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.