Test instructions is: There are a lot of people, have wisdom and charm value, everyone must be taller than others or lower than others to do, or will fight, now find out the largest number of not to fight to participate in the party
This topic just began to listen than people say is the first reorder, the second order, and then find the longest ascending subsequence, In fact, it is not as simple as it is, 1 10,2 12,3 1 This set of data if according to the above statement is wrong, because the need to output subscript, it is obviously wrong, then how to operate now, need a path array to hold something, just at the beginning, I stored the data subscript, Later found that the above situation is not considered, that is, path can be used to store the element in the "queue" is now located in the location is the first place, where you can use two points to find, so that the length of the minimum is unchanged, and then the key point, why I want to reverse the second, the positive sequence can not? If the positive sequence of the words 1 2,2 2, then the value of the path array is 1,2,1,2, whether from the reverse or the positive sequence is not the correct answer, then why to reverse order, reverse to find it, because the words below the largest will and the smallest in a piece, such words, It solves all the problems
#include <iostream> #define INF-9999999999 #include <string.h> #include <algorithm> #include <
Stdio.h> using namespace std;
const int maxn=100005;
struct SA {int x, y;
int p;
};
int cmp2 (const SA a,const sa b) {if (a.x==b.x) return a.y>b.y;
else return a.x<b.x;
} sa A[MAXN];
int DP[MAXN],PATH[MAXN];
int main () {int n;
while (cin>>n) {memset (a,0,sizeof (a));
Memset (Dp,0,sizeof (DP));
memset (path,0,sizeof (path));
for (int i=1; i<=n; i++) {cin>>a[i].x>>a[i].y;
A[i].p=i;
} sort (A+1,A+1+N,CMP2);
int Len=1,pos=1;
DP[1]=A[1].Y;
PATH[1]=A[1].P;
Path[1]=1;
for (int i=2; i<=n; i++) {if (A[i].y>dp[len]) {dp[++len]=a[i].y;
Path[i]=len; } else {Pos=lower_bound (dp+1,dp+len+1,a[I].Y)-DP;
{dp[pos]=a[i].y;
Path[i]=pos;
}}} cout<<len<<endl;
for (int i=n; i>=1; i--) {if (Path[i]==len) {cout<<a[i].p;
if (len!=1) cout<< "";
len--;
}} cout<<endl;
} return 0; }