Beautiful People SGU, beautifulsgu
Longest ascending subsequence O (n log n): http://www.cnblogs.com/hehe54321/p/cf-340d.html
Title: https://cn.vjudge.net/problem/ZOJ-2319
Https://cn.vjudge.net/problem/SGU-199
A data type has two attributes: s and B. Now there are two instances x and y. Define if x. s <y. s & x. B <y. B or x. s> y. s & x. b> y. b, then x and y do not conflict, otherwise x and y conflict. Select the most data among the n data given, so that any two data does not conflict with each other.
Ideas:
The intuitive idea is to sort the original data by the first and second Keywords of s and B respectively, and then calculate the longest ascending subsequence by O (n log n. However, if the number of s in the first data is greater than that in the second data, the number of B in the first data is smaller than that in the second data, it is not certain whether the first or second data is good. Or, if a is not greater than B, a is not necessarily less than or equal to B. (It cannot be done anyway ...)
The correct method is to change it slightly. First, sort by s as the keyword, and then calculate the longest ascending subsequence according to B as the keyword. Of course, the longest ascending sub-sequence here requires s to be strictly less than, not just B Strictly less than, so more details need to be processed. The method used here is similar to this, is some tips http://blog.csdn.net/scnu_jiechao/article/details/40670393
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 struct P 5 { 6 int a1,a2,num; 7 bool operator<(const P& b) const 8 { 9 return a1<b.a1||(a1==b.a1&&a2>b.a2);10 }11 };12 bool cmp(const P& a,const P& b)13 {14 return a.a2<b.a2;15 }16 P a[100100],s[100100];17 int f[100100],len,n,t;18 int main()19 {20 int i,j;21 scanf("%d",&n);22 for(i=1;i<=n;i++)23 scanf("%d%d",&a[i].a1,&a[i].a2),a[i].num=i;24 sort(a+1,a+n+1);25 for(i=1;i<=n;i++)26 {27 t=lower_bound(s+1,s+len+1,a[i],cmp)-s;28 s[t]=a[i];29 f[i]=t;30 len=max(len,t);31 }32 printf("%d\n",len);33 for(i=n,j=len;i>=1;i--)34 if(f[i]==j)35 {36 printf("%d ",a[i].num);37 j--;38 }39 return 0;40 }