//#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> //using namespace std; const int MAXN=10000; struct ele { int inte; int weit; int num; }eles[MAXN]; int cmp(const void *a,const void *b) { struct ele t=*(struct ele *)a; struct ele l=*(struct ele *)b; if(t.inte!=l.inte) return t.inte-l.inte; else return l.weit-t.weit; } int main() { int m[MAXN],q[MAXN]; int i,j; int n; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { scanf("%d%d",&eles[i].inte,&eles[i].weit); eles[i].num=i; } qsort(eles+1,n,sizeof(ele),cmp); /*for(j=1;j<=n;j++) { printf("%d %d\n",eles[j].inte,eles[j].weit); }*/ for(i=1;i<=n;i++) m[i]=1; int t=1,k,f,w,y; memset(q,0,sizeof(q)); for(i=n;i>=1;i--) { k=0; for(j=i+1;j<=n;j++) { if(eles[i].weit>eles[j].weit&&m[i]<m[j]+1&&eles[i].inte<eles[j].inte) { m[i]=m[j]+1; q[i]=j; } if(t<m[i]) { t=m[i]; k=1; //q[i]=j; //printf("%d %d %d\n",i,j,t); } /*if(y<m[i]) { q[i]=j; printf("%d %d %d\n",i,j,t); }*/ } if(k) w=i; } f=1; //printf("%d\n",w); printf("%d\n",t); printf("%d\n",eles[w].num); for(i=w;f!=t;i=q[i],f++) printf("%d\n",eles[q[i]].num); //printf("%d\n",eles[i].num); } return 0; }
重要的是形成路径