Title Link: http://acm.timus.ru/problem.aspx?space=1&num=1112
Test instructions: n segment, to take some, so that the left segment of any segment is not in the interior of a segment.
In fact, it is to take the least number of line segments, so that does not coincide.
Data volume is very small, 100, direct Lis O (n^2) Engage.
First press X from small to large row, then, press X to do the LIS with the previous line of the y ratio, and then record the precursor is OK.
Then output, just beginning to prepare the recursive output, think of the next, did not come out, on the violence and saved again, in fact, can be recursive output, as long as the first one to find a line segment, where the first line is not determined, the use of an ANS variable, see how many layers to recursion.
#include <bits/stdc++.h>using namespacestd;#defineMAXN 105structline{intx, y;} LINES[MAXN];BOOLCMP (line A,line b) {returna.x<b.x;}intDP[MAXN];intPREV[MAXN];intAns =0;voidPrint (intPOS) { if(ans!=1) { --ans; Print (Prev[pos]); } printf ("%d%d\n", LINES[POS].X,LINES[POS].Y);}intMain () {memset (DP,0,sizeof(DP)); intN; scanf ("%d",&N); for(intI=0; i<n; i++) { intx, y; scanf ("%d%d",&x,&y); if(x>y) Swap (x, y); lines[i].x= X,LINES[I].Y =y; } sort (Lines,lines+n,cmp); dp[0] =1; for(intI=1; i<n; i++) { intK =0; intpos =-1; for(intj =0; j<i; J + +) { if(lines[j].y<=lines[i].x&&k<Dp[j]) {k=Dp[j]; POS=J; }} Dp[i]= k +1; if(pos!=-1) Prev[i]=POS; } ans=0; intpos =-1; for(intI=0; i<n; i++) { if(ans<Dp[i]) {ans=Dp[i]; POS=i; }} printf ("%d\n", ans); /*vector<line> Vaj; for (int i=0; i<ans; i++) {vaj.push_back (Lines[pos]); printf ("%d%d\n", lines[pos].x,lines[pos].y); pos = Prev[pos]; } for (int i = ans-1;i>=0;i--) printf ("%d%d\n", vaj[i].x,vaj[i].y); */print (POS); return 0;}
Ural 1112,lis